Pumpkin, Inc.

Pumpkin User Forums

Interrupts and stack

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

Re: Interrupts and stack

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

Hello,

Or you mean that I have to disable all interrups if I'm not on the level of the task? I mean - before I call any functions from the task I should disable interrupts (with OSDisableInts() or directly).

Or to avoid bigger latency of interrupts I should calculate where I have to disable interrupts and where I can stay them enabled.

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 10:35 am

ahhhh ...

yes, you do have to worry about OSTimer()'s stack depth when you are in a task, calling your functions. This is of course true for any complex ISRs ... nothing special about Salvo in this regard.

Anyway, the v2.1 OSTimer() goes 3 stack levels deep. Also, an interrupt that calls OSTimer() consumes a total of 3+1=4 stack depths. Therefore (PIC16) you must disable interrupts (use OSDisableInts()) in your functions that are 4 stack levels deep before calling any functions that go deeper. After calling the functions, call OSEnableInts().

code:
main()                  0
OSSched() 1
task1 2
called function1 3
display 4
OSDisableInts()
refresh 5
flags 6
other 7
OSEnableInts()

In v2.2, OSTimer() takes only one stack level, and therefore the ISR takes 1+1=2.

NOTE: OSDisableInts() and OSEnableInts() are macros.

So, with v2.1, if you are using the timer you must profile your task code and prevent interrupts from happening during function calls at stack depth >4 (PIC16). For v2.2, it will be for stack depths of >6.

You should have interrupts enabled all the time, except for i) this restriction, ii) when Salvo does it automatically, and iii) when you need to control interrupts for other reasons. This will minimize interrupt latency.

I will investigate whether we can make OSTimer() an in-line macro in the full version. In that case, stack depth will be 0, and therefore it will be just like a "simple ISR," with a stack requirement of only 1. That should make integrating OSTimer() into you application very easy, and you won't have to worry about OSTimer() at all -- you just have to guarantee that you don't go deeper than 7 stack depths in your normal application, so there's still room for the interrupt.

Also, OSSched() will be in-lineable for the full version of v2.2. Therefore functions called from tasks will be at a stack level of 2.

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

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

Re: Interrupts and stack

Postby NoMore » Fri Dec 29, 2000 5:09 am

Sorry to interrupt, but just a tiny reminder. It's about Hi-Tech's PIC C specific feature. The main() function is not called but jumped to (or rather goto when main() takes over). So it doesn't consume any stack level.
NoMore
 
Posts: 11
Joined: Fri Dec 01, 2000 12:00 am

Re: Interrupts and stack

Postby NoMore » Fri Dec 29, 2000 5:15 am

Happy New Year, ppl !!!
Prosperity to All !!
Cya in the next Millenium !
NoMore
 
Posts: 11
Joined: Fri Dec 01, 2000 12:00 am

Re: Interrupts and stack

Postby luben » Fri Dec 29, 2000 7:23 am

Happy New Year to the staff of Salvo. Wish you more luck and happiness in the coming year (and not only in the coming).

About the Interrupts. Thank you for your clear reply. Because in your manual is no one word about such problems and because from my own experience I know how badly is to crash the stack, was good that now everything is clear.

My recomendation is to add this note into manual to the topic of OSTimer(), OSSignalXYZ, OSCreateXYZ... all functions that are called from ISR. If you put this like WARNING to show how important it is - you'll avoid many problems. And of course - you should bring the way of how to enable/disable interrupts and how to calculate the depth of the stack levels.

This limitation of course increases the latency of ISR when using Salvo and should be calculated and took in mind. Because if I use very slowly function calls and I disable interrupts in such moments, this will dramatically increase the ISR latency.

In fact if there is enough information about this topic the ISR latency could be reduced just with simple reorganization of the function calls, by simple reducing the stack call depth. So, it's not disadvantage of Salvo, it's just something that should be keep in mind when we program. Salvo brings so much advantages to the users, that such small solveable problem is just nothing.

Regards
Luben

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

Re: Interrupts and stack

Postby luben » Fri Dec 29, 2000 7:33 am

Hello,

I forget to say that in the manual you should add to all the descriptions of the functions the call depth. Something like additional row - "Consumes - 3 stack levels", or "3 levels deep" ....

Especially to the functions like OSTimer(), OSCreateXYZ, OSSignalXYZ.... for all functions that could be called from ISR.

And of course - WARNING message to attention the user and force him to calculate his stack depth. I think that such good product like Salvo desire good manual, right?

Regards
Luben

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

Re: Interrupts and stack

Postby aek » Fri Dec 29, 2000 8:30 am

We'll add the information you suggest to the next revision of the User Manual. Also, we plan on writing an App Note to further explain the details that surround stack depth and interrupts.

Unfortunately, it's not realistically possible to reduce the stack depth of the OSCreateXyz() and OSSignalXyz() services. That's because to "unwrap them" will consume much more ROM than is acceptable. Right now, the various OSSignalXyz()s all call a single OSSignalEvent(). OSSignalEvent() calls OSInsEliqQ(), which is also called from various places. This all keeps the codesize to a minimum, but as you have observed, causes some problems with small call stacks if OSSignalXyz() is called from an interrupt.

I believe this will be the best-case scenario for the v2.2 full version of Salvo:

1) OSTimer(), when called, has a stack depth of 1. When invoked as a macro, OSTimer() has a stack depth of 0.

2) OSSignalXyz() has a stack depth of 3. It cannot be invoked as a macro.

3) OSSched, when called, has a stack depth of 1 for itself, and therefore tasks run at a stack depth of 2. OSSched() can be invoked as a macro, reducing the running tasks's stack depth to 1.

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

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

Re: Interrupts and stack

Postby aek » Fri Dec 29, 2000 9:28 am

re: main() being jumped to ... you're absolutely correct, and that's why my responses below show main() at a stack depth of 0, i.e. it does not consume a stack level.

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

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

Previous

Return to Coding

Who is online

Users browsing this forum: No registered users and 1 guest

cron