Go Down

Topic: mini RTOS [sic] (Read 4 times) previous topic - next topic

melka

#5
Aug 04, 2008, 08:35 pm Last Edit: Aug 05, 2008, 12:39 am by melka Reason: 1
Just a thought, but why not use a port of the freeRTOS project (and eventually rewrite some parts of it so that it works with the off-the-shelf-16Mhz-crystal Arduino) ?
http://www.freertos.org
http://www.kieltech.de/uweswiki/FreeRTOS

mem

Hi melka,

I agree with westfw's first post, its overkill for any arduino applications I can think of. I would be interested to hear about an application that would fit on an arduino board with room to spare for a RTOS that that couldn't be done with a simple cooperative scheduler.

mlindeblom

I agree that what is being looked for is a simple scheduler and a os that keeps reasonable time.

Support for resource contention and typical inter task communications is well beyond the requirements to implement a simple data logger or simple control system with time stamped event logging.

It is true freeRTOS could form the basis for processing/wiring; however: you would most likely see increased memory, CPU and complexity.  I would hold off until you need an integrated IP stack and web support.

There may be a need for a fork - simplicity versus web support.

MartinFick

#8
Aug 04, 2008, 10:22 pm Last Edit: Aug 04, 2008, 10:31 pm by MartinFick Reason: 1
I would agree that some type of hopefully ISR driven core scheduling mechanism would be nice, especially since I can't get FrequencyTimer2 to work properly with delay() (see me other thread on this).  But, I also have a simple suggestion to perhaps make programming delays without an ISR a little better in some cases than using the delay() function.  My suggestion is to add two new function that together would perform similarly to the way delay() works, but they would split the delay job into two jobs so that more accurate scheduling can be achieved.  The two calls would look something like this:

unsigned long millisAdd(int ms)

and

delayUntil(unsigned long  timems)


This would allow one to schedule more regular delays by taking into account the time it takes to execute code between the delays.  For example imagine wanting to do something every 10ms coded like this with delay():

Code: [Select]

void loop() {

 // execute some variable execution length code that may take anywhere from 1 to 5 ms

 delay(10);
}


This will lead to very inconsistent timing results.  However, with these two new functions, one could easily code up the following:

Code: [Select]

void loop() {
 unsigned long timems = millisAdd(10);

 // execute some variable execution length code that may take anywhere from 1 to 5 ms

 delayUntil(timems);
}

and get much more accurate results.   These two functions should be extremely easy to implement since it basically just involves splitting the code to delay() in two.  Instead of adding the millisAdd() function, it would probably be easy enough to simply overload the current millis() call to take an optional second argument which would take the current millis() value and add ms to it.


While the utility of this solution over using an ISR may not be quite so obvious for continuously repeating patterns, if one imagines doing something for a limited amount of iterations (or varying consecutive delays) this becomes much more useful.  Example of code which is not very ISR timing friendly:

Code: [Select]

 // Changing delay interval
 unsigned long timems;
 for(int i=0; i <8 ; i++) {
    timems = millisAdd(10 * i);
   // execute some variable execution length code that may take anywhere from 1 to 5 ms
   delayUntil(timems);
 }

// Or changing tasks and delays.
 timems = millisAdd(5 * i);
  // execute some variable execution length code that may take anywhere from 1 to 3 ms
 delayUntil(timems);
 ...
 timems = millisAdd(20 * i);
  // execute some variable execution length code that may take anywhere from 1 to 5 ms
 delayUntil(timems);
 timems = millisAdd(15 * i);
  // execute some variable execution length code that may take anywhere from 1 to 10 ms
 delayUntil(timems);


mem

I have posted the first cut of the simple scheduler library.
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1217881285

I would be interest in comments regarding is suitability for performing the kinds of tasks that people posting on the topic of scheduling have in mind.


Go Up