Pumpkin, Inc.

Pumpkin User Forums

Re: Priority

If you can't make Salvo do what you want it to do, post it here.

Re: Priority

Postby luben » Sun Dec 03, 2000 8:24 am

Hello,

I read the manual for Salvo and on page 71 is one example for LEDs control (listing 25).
I have a question - I saw that you applied different priority to the tasks, that's OK. For the one application - 10, to the other - 2. Will something change is I apply priority 3 and 2 respectively. I mean - your RTOS behavior does it depend on the value of the priority, or it just operates on the idea - bigger <-> lower.

And on page 74 you wrote that if TaskBlink() has lower priority then TaskCount() and TaskShow() it will never run at all? As I see both TaskShow and TaskCount use some calls to the kernel (OS_Yeild() and OS_WaitSem()... ) and they could bring some time to other applications with lower priority. Does it mean that lower priority tasks could get some time only if all other applications are in DELAY() state???

Excuse me, I'm a begineer in Salvo.

Regards
Luben

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

Re: Re: Priority

Postby Salvo Tech Support » Sun Dec 03, 2000 9:16 am

Hi Luben.

1) No, it wouldn't make any difference if instead of task priorities of 10, 10 and 2, they were 1, 1 and 0, respectively.

2) A low-priority task can only run IF it is eligible to run AND IF no higher-priority tasks are eligible to run. TaskCount() is ALWAYS eligible. TaskBlink() runs because it becomes eligible when its delay expires, AND it has the highest priority of the three tasks. If it had a lower priority, it would become eligible after its delay, but would never run because TaskCount() has a higher priority. A low-priority task has a chance to run whenever all higher priority tasks are either delayed, waiting, stopped or destroyed.

The point of the example is for the reader to appreciate the dynamics of the system, based only on the (constant) task priorities and the (time-varying) task states.

--------
Salvo Technical Support
Please request all tech support through the Forums.
Salvo Tech Support
 
Posts: 173
Joined: Sun Nov 19, 2000 12:00 am

Re: Re: Priority

Postby luben » Mon Dec 04, 2000 8:34 am

Hello,

Thank you very much for your support. Your forum is really grate and it's good that you answer so quickly and exactly.

So, if the task has lower priority it could run only if all higher priority tasks are in delete, wait or delayed state, right?

My question is - if the lower priority task starts and don't return the control to the scheduller (from OSyeild(), Wait, or Delay) the higher priority tasks could not run again. That means - I have to care that all my tasks support some structure - they should never have loops that wait pin value forever for example.

Regards
Luben

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

Re: Re: Priority

Postby aek » Mon Dec 04, 2000 9:09 am

Hi Luben.

1) Correct.

2) Every task must return control to the scheduler or else no other tasks can run -- this is how cooperative scheduling / multitasking works. You are right that with Salvo you should never have a loop that waits for a pin value.

But it's silly to do that anyway, because your program could be doing something else instead of looping. That's what OS_WaitXyz() is for -- if the pin value is already correct, then the task continues. If it's not, then the task yields back to the scheduler and enters the waiting state. Now, other tasks can run. When the pin changes to the correct value, then the waiting task is made eligible again. This is what event-based multitasking is all about.

For RTOS beginners, using events may also be the hardest thing to understand. In your example, let's assume you're using the PIC's PORTB interrupt-on-change feature. In Salvo, what you would do is write an ISR that happens whenever the pin changes. When it changes to the right value -- say you're waiting for it to turn to logic 1 (5V) -- you call OSSignalSem() from the ISR. This then automatically causes the waiting task to become eligible again, and eventually run.

code:
void interrupt ISR (void)
{
...
if ( PORTB_changed && (my_pin == 1) ) {
OSSignalSem(SEM_MY_PIN, 1);
}
...
}


void myTask ( void )
{
for (;;) {
...
OS_WaitSem(SEM_MY_PIN, ...);

/* now pin is the right value, proceed. */
...
}
}


That's it!

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

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

Re: Re: Priority

Postby luben » Tue Dec 05, 2000 10:29 am

Hello,

Thank you for the reply.

I used to work with some Motorolla processors where you can use big amount of RAM and where you can make multitasking like Windows do - every task don't care for it's structure. In such "big RAM" processors you can implement easy full multitasking using interrupts and every task is like normal program and can communivcate with other programs via messages.

After I started working with PIC I found that it's impossible to do any good multitasking, but seems that I wronged. With Salvo it's possible to do multitasking, well, with some small limitations. I will recommend your software to my friends, I think it is one excellent product.

Regards
Luben

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


Return to Coding

Who is online

Users browsing this forum: No registered users and 2 guests

cron