Pumpkin, Inc.

Pumpkin User Forums

Stopping Multitasking

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

Stopping Multitasking

Postby garrett » Wed Jul 01, 2009 6:44 am

I am running on an MSP430 with two timers.
Right now Timer A is running an ISR for OSTimer().
I have a time critical task that needs to use a timer. What I would like to do is temporarily stop the OS so I can do my time-critical code, and "reuse" timer A for my routine, then restore timer A for the OSTimer tick, then restart the OS right from where I left off.
My routine is not an ISR but just a standard function called by a button press.

Is there a good way to do this with Salvo?

Thank you.

garrett
 
Posts: 8
Joined: Tue Oct 21, 2008 11:00 pm
Location: Cranberry Township PA USA

Re: Stopping Multitasking

Postby aek » Thu Jul 02, 2009 8:47 am

That is not the right approach ...

1) First, no multitasking happens when OSSched() is not called. Therefore, if you have a task that "needs to run while there is no multitasking", then just stay in the task until you're done.

2) A timer need not be dedicated to calling OSTimer() exclusively. You can use it to do other things, too. E.g. do something at a high rate, and also prescale it down inside the ISR, e.g. have it call OSTimer() only once every 10 times.

3) OSTimer() is a very fast call -- probably around 20-30 instructions max. So there is really no penalty to "leaving it in".

4) Salvo 4 has advanced interrupt configurability, which can handle any possible scenario where you have high performance requirements and the need to prevent Salvo from taking too much processor time while in user-critical interrupts -- see the Salvo 4 User Manual.

5) The problem that you will have with stopping and restarting the "Salvo timer" (other than it is unnecessary) is that you will introduce major timing jitter than will cause delay and timeout timing errors, leading to debugging headaches.

6) Salvo's built-in supertimer can handle up to 255 "lost ticks" before screwing up Salvo's timing long-term.

The right way to do this is to

i) simply leave TimerA to call OSTimer() as required,

ii) add more functionality to TimerA, but ensure that OSTimer() is still called at its normal rate (e.g. 100Hz, which is quite slow),

iii) stay in your critical task (while all TimerA interrupts occur) for less than 255 system ticks,

and you're done.

If you still insist on not doing it this way, then basically you must figure out how many ticks elapsed while you were failing to call OSTimer(), then loop on said counter while calling OSTimer() before allowing normal multitasking to continue, and do final corrections thereafter (because it takes time to call OSTimer() that many times). Note that you have to make a careful calculation (which will cost you a 16-bit or larger timer anyway) to do this correctly, so it is most definitely not recommended.

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

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

Re: Stopping Multitasking

Postby aek » Thu Jul 02, 2009 8:49 am

IOW, think about doing things in parallel.

Note that this parallel approach avoids any issues with Salvo critical sections (which disable interrupts when Salvo is in a critical section) affecting your special task, because you won't be making any Salvo calls during that task (and because OSTimer() does not invoke any Salvo critical sections).

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

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

cron