[sdiy] RTOS (was Re: sine wave floating point conversion issue)

Veronica Merryfield veronica at merryfield.ca
Sun Feb 26 07:02:58 CET 2012


On 2012-02-25, at 1:45 PM, Olivier Gillet wrote:

> This works well under the assumption that each task will complete
> rapidly. As soon as a task can unpredictably take more time to
> complete (say 10 ms in your case), and you still want the other ones
> to be executed on a regular time base, this solution won't work. There
> are several options then:
> * Do everything time critical in a timer ISR, and everything "slow"
> and not time-critical in the main code.
> * Allow the "slow" task to return mid-way, for example by using
> coroutines http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
> . The drawback is that you'll have to sprinkle TASK_SWITCH or whatever
> macro you have defined everywhere in your tasks code to indicate where
> it's OK to break from.

The usual way to implement this is to create a state machine where the context is managed explicitly in code. I have on many occasions used this technique and on several used one state machine and a number of context structures - serial routines dealing with weigh scales in chemical plants for instance. In our world, handling multiple midi in sources could be done this way.

> * Use a proper RTOS.

The trade off here is the context switching time verses the pre-emption of tasks and the various other features that usually come with an RTOS. Saving the processor state, finding the next task to run, restoring the state and anything else required (cache flush, memory management and such in bigger systems) can take a significant amount of time. Depending on the flavour of RTOS, it might impose constraints on interrupt processing and so on. An RTOS does not guarantee to make real time systems any more real time and often an RTOS requires overhead horse power. Where it can sometime score is if the RTOS exists for different platforms, something Matthew migth benefit from, or where the system are very complex.

> I personally think that an RTOS is overkill for something at the level
> of complexity as a synth project (except maybe if it's a
> workstation-style thing). I wouldn't do a quadrocopter without though
> :) And in Dan's case, who is doing sound generation or Fxs on an AVR
> clocked at 16 MHz, this is close to insane.

More or less. Depending on the quadrocopter, I still might not :) 


More information about the Synth-diy mailing list