Pumpkin, Inc.

Pumpkin User Forums

Interrupts and stack

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

Interrupts and stack

Postby luben » Thu Dec 21, 2000 1:11 am

Hello,

I can't figure out the way Salvo is processing the interrupts. Immagina that I have a task, that could be up to level 6 of stask. And in this moment the interrupt comes. It consumes one level more. In addition the task is on level 1, taht means - from the interrupt you can't call any functions at all. So, how you can manage the OSCignalBinSem() from interrupt, if it's called with fuction call? Or what about OSCreateBinSem();

regards
Luben

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

Re: Interrupts and stack

Postby aek » Thu Dec 21, 2000 11:07 am

Hi Luben.

The stack situation is no different from the non-Salvo application that has a function call tree that starts in main() and extends an additional seven functions deep -- if you get an interrupt while in that last function, then the interrupt can't call anything without overflowing the call...return stack.

But don't confuse Salvo's maximum call...return stack depth with the overall depth you have available. The maximum Salvo call...return stack depth occurs inside Salvo services only. Here's an example showing the function calls and call depths (PIC16 with 8 stack levels) for a Salvo service and a user function inside a task:

code:

main() 0
OSSched() 1
TaskA() 2
OSSignalSem() 3
OSRtnEcbP() 4*
OSSignalEvent() 4*
OSInsEligQ() 5*
myFn() 3

*: interrupts are fully disabled at these levels.

From the above you see that functions called from within a task are at a stack depth of 3, and Salvo "never goes deeper" than a stack depth of 5.

From the above, you can also see how Salvo handles interrupts, e.g. how it's able to allow calls to OSSignalBinSem() from an ISR. That's because the Salvo services disable interrupts at level 3. Therefore if an interrupt that calls OSSignalBinSem() occurs immediately after the task calls OSSignalSem() but before OSSignalSem() can disable interrupts, OSSignalBinSem() still has four stack levels that it can use (8 - 3 (in Task) - 1 (for interrupt)).

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

Re: Interrupts and stack

Postby aek » Sat Dec 23, 2000 1:29 am

Interrupts should normally be enabled in your application.

Salvo services that need interrupt control disable interrupts, do something, and then re-enable interrupts.

Salvo does not unilaterally enable interrupts except in one case -- interrupts are automatically enabled after OSInit() if the idle task is enabled. If this is a problem, you should disable interrupts via OSDisableInts() right after OSInit(), and then re-enable them when you're ready (e.g. just before the OSSched() loop).

So, you might say that Salvo expects or needs interrupts to be normally enabled. It will disable, then re-enable them during normal operation. If you enable interrupts before entering the infinite loop with OSSched(), interrupts will be enabled when your tasks are running.

Advanced interrupt control is available to source code users by redefining Salvo's interrupt control macros.

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

Re: Interrupts and stack

Postby luben » Sat Dec 23, 2000 5:54 am

Hello,

In your example you use only Salvo functions. Because they are called from the main level it's no problem to calculate the moments where to disable interrupts.

But what about the other part of the program - if I have to care for interrupt levels I have to know the depth of the OSTimer(). How much consumes the OSTimer() procedure.

It's a good idea in the manual to include the maximal depth of routines that are critical, like OSTimer().

Regards
Luben

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

Re: Interrupts and stack

Postby Salvo Tech Support » Sat Dec 23, 2000 9:38 am

Hi Luben.

Yes, that's a good idea.

Off the top of my head, in v2.1, the OSTimer() stack depth is 3.

In v2.2, it's 1.

--------
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: Interrupts and stack

Postby luben » Sat Dec 23, 2000 12:02 pm

Hello,

I have some questions about the idea of interrupts in Salvo.

When they are enabled and when disabled. From what I read in the manual when I call some Salvo fuctions it's disabled if the levels exceed some value.

And what about my main code? When I'm into my task and don't call Salvo fuctions - are interrupts enabled?

Because if I don't know the behaviour of the Salvo I can't predict the behaviour of my whole program.


egards
Luben

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

Re: Interrupts and stack

Postby luben » Wed Dec 27, 2000 8:55 am

Hello,

There is something that I can't understand, but it's very important.

If I have task that calls functions with stack 5 levels deep (it's allowed, right?). And my timer interrupts every 10ms the process. What will happen if the interrupt comes when I'm in the "deepest" function branch (I already consumed 6 of the stack levels). The OSTimer() has some stack calls too. How the OSTimer() understands that it's dangerous to call anything? Or the interrupts are disabled in my tasks until I'm not on the "base interrupt level".

With two words - what are the limitations of the interrupts that comes from Salvo. What is the deepest allowed stack level? How much levels consumes Salvo with and without OSTimer(). And if I do OSSignalXYZ from interrupt - how many additional levels will consume this.

For simple projects like in the manual such questions are unvisible and don't sound seriously, but for one heavy project, with many function calls it's important to know exactly the behavior of the Salvo and interrupts.

Regards
Luben

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

Re: Interrupts and stack

Postby luben » Wed Dec 27, 2000 9:02 am

Hello, to be more exactly:

main() 0
OSSched() 1
TaskA() 2
Function1() 3
Function2() 4*
Function3() 5*
Function4() 6* <---- INTERRUPT
......

If interrupt due to the timer overflow occures and needs OSTimer() call or OSSignalXYZ(), what will happen. Or interrupts are disabled from Function2 up to Function4. And if disabled - how you make this, how you watch the stack level?

Regards
Luben

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

Re: Interrupts and stack

Postby aek » Thu Dec 28, 2000 8:20 am

If an interrupt occurs when interrupts are disabled, as you show in your example, then the timer interrupt will not be serviced until interrupts are re-enabled.

I.e. it will be serviced after the Salvo service that controlled interrupts (e.g. OSSignalSem()) re-enables interrupts. OSRtnEcbP(), OSSIgnalEvent() and OSInsEligQ() do not control interrupts. Therefore OSTimer() and its call chain cannot occur at the stack depths of 4 or 5 in my example, but can occur at a stack depth of 3 or less.

If possible, we will create a version of DemoD1 to run on the MPLAB-ICD that you have. There, you can observe a multitasking Salvo application will calls to OSTimer() from the ISR. It has a maximum Salvo call...return stack depth of 5.

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

Re: Interrupts and stack

Postby luben » Thu Dec 28, 2000 9:52 am

Hello,

Maybe I was not very exactly in my question. I know that Salvo controls the stack levels when we are talking about calling of OS functions and macros.

I think that there is potential problem if my program is currently in stack level 7 (from 8 possible) and interrupt from timer occures. This will consume the last level 8. And if the OSTimer() is called - the stack will crash. How OSTimer() understands where I'm in the call graph (I'm not talking about OS functions)

Example
main() 1
task1 2
called function1 3
display 4
refresh 5
flags 6
other 7 <..... here timer interrupt occures

What will happen in this case?

Regards
Luben

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

Next

Return to Coding

Who is online

Users browsing this forum: No registered users and 2 guests

cron