Pumpkin, Inc.

Pumpkin User Forums

Salvo Features

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

Salvo Features

Postby luben » Sun Nov 19, 2000 8:09 am

Hello,

With two words it's impossible to manage 2 or more slowly tasks with other quick tasks in current version of Salvo. I will be surprised if you could do this, because in the real C and with this "no stack" architecture of PIC it's just near impossible.

As I told you I got some way how to do this with unlimited number of very slowly tasks, but unfortunetely I don't have such resourses and so many people to finish such giant job.

The idea has two parts (I'm afraid that if I should explain everything in details it can take many pages):

1. The libraries, used in C should be remade. Each function should be parted on many small blocks and each block should be executed for limited period of time. If some function are waiting forever for some event - they should only check once the event, then to set/reset some flags and return back the control.

2. The algorythms and whole construction of C program source code should be transformed (this is the heaviest part of the job) in that way:
- whole user program should be separetatd on small blocks, each block is executed within limited time. If program waits some response from pin or flag it should not wait in this point, but only set/reset some flag and return the control.

And there is an intelegent kernel that manages wich "block" should be run. I make such kernel with easy "switch" construction. The other care of the cernel is to save / load the variables from/to different blocks. Inside the blocks are simple calculation of the next step (which block should be run after finishing the execution of the current block).

There are no theoritical limitations to do this - you can manage as much blocks as you wish and the only one limitation is the RAM, not the architecture of the processor.

The real problem is that there is no mathematical models how to convert one structure to other, how to "translate" the normal C algorythm to such structure. That's why I gave up - it's not a job for single man. I can make even now working program with 3-4 very slowly tasks, but the C source becomes very strange and complicated. I think that this need or some other language, or deep remade of the C compiler. In your case you make something like smart libraries that make easier to generate working multitasking. In fact you don't break the rules of the C language, you just add more value to libraries and simplify the maintance of the many tasks in the same moment.

From what I saw in your demo, your product is really excellent and if I had money I would buy it immediately and without hesitation. I recommend it to all people who tried once the giant advantage of the multitasking. Grate and smart product is Salvo - that's all.

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

Re: Salvo Features

Postby aek » Sun Nov 19, 2000 9:17 am

Hi Luben.

Perhaps I don't really understand what you mean by "slow tasks." Also, what do you mean by "smart libraries?" Can you give an example?

As long as you can place OS_Yield()s in a task, you can make it as "slow" as you want ...

Your Point 1.: I assume you mean _your_ libraries, not HI-TECH's or Salvo's. Salvo's OS_WaitXyz() does just what you want, but waiting on events must occur at the task level, not in a function called by a task ... One big benefit of using Salvo, which is not immediately apparent to multitasking novices (but I'm sure you already know), is the use of events to ensure that you never spend any processor cycles waiting for some event.

Your Point 2.: If you could "unwrap" the algorithm / library function to be within a task, then you can use OS_WaitXyz() to "return the control" and let other tasks run.

Your block- and switch()-based construction sounds a lot like a state machine. Keep in mind that a state machine can easily exist within a Salvo task, e.g.

code:
void TaskWithStateMachine ( void )
{
static char state = 0;


for (;;)
{
switch (state)
{
case 0:
{
do something;
state++;
OS_Yield();
}

case 1:
{
do something else;
OS_WaitSem();
state++;
}
...
}
}
}


As long as you remember to maintain static variables inside the task, it can "pick up where it left off" at an arbitrarily later time.

The memory requirements for events (in this case, the things your blocks wait for) are extremely small -- typically 3-4 bytes per event on a PIC16.

So the advantage of the Salvo task containing a state machine over a simple state machine in a main() loop is that you can "leave" that state machine and "enter another" all under multitasking program control. In other words, multiple state machines, all progressing through their states at different rates, are very easy to manage. And you can wait for an event within a state machine ... while waiting, the task consumes zero processor cycles, freeing your processor to do the other tasks.

Of course, what you describe can also be done, with a time-sliced multitasking approach. However, the lack of a stack in the PIC makes this essentially impossible, as one cannot read the function's call tree when the current task's time slice expires.

From what you've described, the only difficulty I see in using Salvo is to separate your program into small blocks, each of which is executed faster than the system tick time. Blocks that logically follow one another don't even need a state machine. More complicated program flow can be managed with a state machine within a task, or by using Salvo messages (events). You don't even need to "manage" which block will run, as is handled in your C code directly.

[This message has been edited by aek (edited November 19, 2000).]

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

Re: Salvo Features

Postby luben » Sun Nov 19, 2000 10:19 am

Hello,

I'm using HiTech PIC for programming PIC. I have some questions:

1. is it possible for your product to support such project:
. you have one very slowly task, that needs for normal execution 4-5 s (it calculates in floating point some very complicated calculations).
. one another slowly task that makes other calculations, but within 1 s
. 5 other tasks that have to execute every 20ms.
. one high priority task from interrupt

My question is - if the calculation with floating point are so slowly, is it possible to make multitasking with them. It's possible only if you supply special libraries for mathematical calculations.

I'm doing some multitasking, but I part the whole job on small pieces and every piece is executed for some limited time. I have something like kernel that cares which piece is executed now. But this is very complicated and hard to adjust for different projects. The biggest problem is how to make on pieces such operations like floating point calculations, that's why I gave up.

2. What is the minimum time for time delays. Can I set for example time for 104uS (one bit delay in 9600 bps RS232 interface). And what is the resolution - 1 cycle, 10 ms.... ?

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

Re: Salvo Features

Postby Pumpkin Incorporated » Sun Nov 19, 2000 10:48 am

Hi Luben.

First, to answer your second question:

The minimum time for delays is a function of how fast OSTimer() and the interrupt service routine's (ISR) overhead runs. As a rule of thumb, your Salvo system tick rate should be 5-10 times slower than this. Otherwise your system will be overloaded by the Salvo system timer, and your "main loop" and the tasks in it won't have much opportunity to run.

You set the system tick rate by calling OSTimer() at a rate that you decide.

As an example, if OSTimer() requires 200 instruction cycles to execute, and your ISR overhead (save and restore WREG, STATUS, PCLATH, etc.) is an additional 50 instruction cycles, then at 4MHz clock (1us instruction cycle) I would recommend a system tick rate no faster than 1.25ms (800Hz). I.e. the timer interrupt that calls OSTimer() should occur no faster than every 1250us.

The Salvo calls that use the timer (e.g. OS_Delay()) are accurate to one system tick.

So, bit-banging RS-232 at 9600 baud with a Salvo task is really not feasible on a PIC running at 4MHz. Lower baud rates, combined with higher clock speeds, could make this possible. Better to do the bit-banging with a combination of an ISR and a state machine, and then have a Salvo task handle the higher-level communications on a byte-by-byte basis.

Also, note that there is another issue here: if Salvo were to disable interrupts for more than 104us (or practicalluy speaking, half that, or 50us), then the RS-232 bit-banging would fail. On a 4MHz PIC, Salvo will definitely disable interrupts for more than 50us, so you would have to use a faster PIC in order to combine Salvo multitasking with bit-banged serial communications.

Using the built-in serial port at 9600 baud, with interrupts occurring every 1.2ms for received and transmitted data, is not a problem with Salvo.

Signature block
Pumpkin Incorporated
 
Posts: 11
Joined: Mon Aug 28, 2000 11:00 pm
Location: City, State, County

Re: Salvo Features

Postby Pumpkin Incorporated » Sun Nov 19, 2000 11:22 am

Hi Luben.

Now to your first question:

You are correct in recognizing the problem with library functions that take a long time to execute.

If I understand you correctly, you have two operations that each take an extremely long time, and hence an extremely large number of instruction cycles, to reach a result. You want them both running at the same time. I presume you are iterating over a very large number ...

The 5 tasks that execute every 20ms and the "high priority task from interrupt" (which I'll interpret as simply some code that must run when an interrupt occurs) are easily implemented with Salvo.

Your question is complicated by the fact that you have two slow tasks. If you had only one, and you were not using Salvo, then one could imagine that your program would look like:

code:
main()
{
while (1) My5secTask();
}

and everything else would be handled in interrupts.

But clearly you want two slow tasks, with their execution interleaved. To do this with Salvo, you would need to insert context-switching macros (i.e. OS_Yield()) inside the slow tasks. For example:

code:
void My5secTask( void )
{
for (;;)
{
setup long calculation;
static char j;

do {
libFn1();
OS_Yield();
libFn2();
OS_Yield();
...
for ( j=0 ; j < 100 ; j++ )
{
libFn7();
OS_Yield();
}
...
libFnN();
OS_Yield();
} while (error > d);
printf("result is %f
", result);
}
}

The code above assumes that each library function executes in a relatively fast time, e.g. < 2000 instructions for a 4MHz PIC for your example.

The only requirement for placing OS_Yield() is that it must be at the task level -- it cannot be in a function called by a task. Therefore it cannot be in a library function. But it can be anywhere in a task, including in a nested for() loop, or in a switch() statement, etc.

Since HI-TECH's library functions are written to execute in a reasonable number of instructions, I suspect that you can implement your own, complicated algorithms at the task level, making low-level library function calls (e.g. sqrt()) inbetween calls to OS_Yield().

There is no limit to the number of unique context switches in a task. As a Salvo programmer, you must ensure that the maximum time between context switches in a task is less than the system tick time.

Also note that in My5secTask() above, interrupts are always enabled.

[This message has been edited by aek (edited November 19, 2000).]

Signature block
Pumpkin Incorporated
 
Posts: 11
Joined: Mon Aug 28, 2000 11:00 pm
Location: City, State, County

Re: Salvo Features

Postby luben » Mon Nov 20, 2000 7:28 am

Hello,

I agree with all what you said. If I can make my program on slices that could finish in short time it will be OK.

"Slow task" is one task that will be exuted for time, that's much bigger then the multitasking switch time. And couldn't be broken into smaller pieces.

For example - can you tell me how to make on slices floating point exponent or logarithm function? Or tangens? ( in fact it's not impossible - I can make my own library, but this will take of my time). That's the problem - such functions consume a lot of mashine time. If you begin such function it's doubtful that you can finish it in some short time. And if you calculate in the same time 2-3 such functions? One real multitasking could support many "slow" tasks.

In fact, if I do only one "slow task" your software could support it into forground and all other tasks into background (interrupt). So, if I reduce all my slowly tasks to one, everything will fit. That means - it's easier to adjust my project to your software, then to make new libraries and complicated constructions :-)


This is not a problem of your software, but on the PIC architecture - the stack is not readable and writable from user programs. If you have PUSH and POP instructions full multitasking is no problem.


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 1 guest