Pumpkin, Inc.

Pumpkin User Forums

OS calls from within subroutines

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

OS calls from within subroutines

Postby James » Mon Dec 03, 2001 9:11 am

I've looked over Salvo 2.2 a little and I can see why you should, in general, not make OS calls from interrupts that invoke the scheduler and might result in a context switch. But, it seems like if you only did it from one interrupt in one place, it would work. Is this incorrect?
James
James
 
Posts: 12
Joined: Thu Oct 04, 2001 11:00 pm
Location: San Diego, CA, USA

Re: OS calls from within subroutines

Postby aek » Mon Dec 03, 2001 11:41 am

Hi James.

You can make certain OS calls from interrupts already -- things like OSSignalSem(), etc. To do so, though, you must have the HI-TECH PICC interrupt_level pragma set accordingly. That's what all the OSCALL_OSXYZ configuration options are for, and that's why there are variants (a, b, f) of each library.

You can't, however, do a context switch from inside an ISR. That's because there's no "stack context" saved (this is partly a PIC issue, though other OS'es usually have this restriction, too). Think of it this way: if you did a context switch from inside an ISR, what does the stack "above" the ISR look like? It could be very deep (lots of nested subroutines), or it could be very shallow. When you resume after the context switch, the stack "above" will most likely be completely different.

Since Salvo doesn't store stack info (because of limited RAM), your program will vector into some random place if you do a context switch from within an ISR. Not good.

From an overall programming standpoint, I find it useful to regard interrupts as the "driving force behind events". This way, whenever an external or internal event happens, it's chained in some way to an interrupt handler, and that usually means that an event is signaled via OSSignalXyz().

There are times when it's useful to be able to "get at" an event from inside an ISR -- for that, use OSTryXyz() or OSReadXyz().

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

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


Return to Coding

Who is online

Users browsing this forum: No registered users and 2 guests

cron