Multitasking operating systems

BrotherV
Fri Dec 04, 2015 12:52 pm
Hi
Arduino does not support “REAL” parallel tasks (aka Threads), so I want to introduce ArduinoThreads library.
Multithreading is mainly found in multitasking operating systems. Multithreading is a widespread programming and execution model that allows multiple threads to exist within the context of a single process. These threads share the process’s resources, but are able to execute independently. The threaded programming model provides developers with a useful abstraction of concurrent execution. Multithreading can also be applied to a single process to enable parallel execution on a multiprocessing system. https://en.wikipedia.org/wiki/Thread_(computing)

ArduinoThreads is a library for managing the periodic execution of multiple tasks. Download the Master branch from gitHub.https://github.com/ivanseidel/ArduinoThread


martinayotte
Fri Dec 04, 2015 2:13 pm
You can also used the FreeRTOS that is already ported for STM32.

stevech
Fri Dec 04, 2015 6:15 pm
martinayotte wrote:You can also used the FreeRTOS that is already ported for STM32.

RogerClark
Fri Dec 04, 2015 8:04 pm
As well as using Finite State Machine(s)..

Don’t use the delay function. (well, you can use short delays for specific purposes but its generally best to avoid using delay() )

Either use the FSM to handle the delays or use hardware timers and interrupts.
e.g. see the Arduino “blink without delay” example, for one alternative method to using delay.

On the STM32 you can also make use of DMA for some tasks, hence still allowing then microprocessor core to execute code , while the DMA hardware does things like transferring to or from SPI ( or serial or memory or even from GPIO)


mrburnette
Sat Dec 05, 2015 12:55 am
IMO,
Everyone seems to be missing the Op’s point, a class-library is available to perform pseudo-threading on the uC. This is educational, but will impose some overhead.

I’ve looked over the class implemention and example. I see no problem in the approach, but limitations could show in testing, which I did not perform.

To the comments, “yes” all are correct. We have all used a multitude of approaches to implement code that does not stall; the pseudo-thread implemention is just another approach.

Ray


martinayotte
Sat Dec 05, 2015 2:51 am
Few months ago, I’ve faced some bottleneck in a daily job project, a LPC1768 under mBed with RTOS.
Those past months, I’ve been re-design this board with STM32F405, still lots of work to finalize testing.
But, early in re-design, I decide to go all the way with stm32duino, and with help of people here, the FreeRTOS port was the way to go.
I’m happy with it since weeks. I’ve even think (if “time-missing-indredient” is there) to try to port it to ESP82266 world … ;)

stevech
Sat Dec 05, 2015 5:44 am
Interesting that ChibiOS (an RTOS like FreeRTOS), is the basis of Viper (Python) on the Particle.io Photon board (STM32).
And the SAME hardware, when used with Particle’s Arduino-alike C code environment, runs FreeRTOS.

These both permit the WiFi networking and other management to run so long as the user program doesn’t hog all the CPU time.

They’ve both done well to “hide” the existence of the RTOS from the typical user. But advanced users can make RTOS calls to create tasks.

(RTOS has long used the term task, where each task has its own stack. Other worlds use the term thread. There are some single-stack “threaded” schedulers, and then can task switch based on time-slices or yields by the thread.)

Still, my experience is that finite state machines can handle 90%+ of the situations with tiny code and with simplicity.


ahull
Sat Dec 05, 2015 12:11 pm
stevech wrote:
Still, my experience is that finite state machines can handle 90%+ of the situations with tiny code and with simplicity.

BrotherV
Sat Dec 05, 2015 8:24 pm
ahull wrote:stevech wrote:
Still, my experience is that finite state machines can handle 90%+ of the situations with tiny code and with simplicity.

ahull
Sat Dec 05, 2015 9:52 pm
BrotherV wrote:
Actually Iran is located in West of India. the weather is good but we don’t have good rainfall up to now. Iran is spectacular country, Shiraz and Isfahan are specially spectacular in spring. ;)

mrburnette
Wed Dec 30, 2015 12:13 am
Interesting paper:

RTOS analysis for microcontrollers-Warning PDF=45KB

For systems comprising 16 or more tasks, the Non-
Preemption Group concept, combined with integrated
priority allocation and schedulability analysis results in
a reduction in the number of preemption levels re-
quired by a factor of 4 or more

Ray


stevestrong
Tue Jun 28, 2016 12:07 pm
I found this, it may be useful for some of us:
Multithreading example using a minimal context switcher

mrburnette
Tue Jun 28, 2016 12:17 pm
stevestrong wrote:I found this, it may be useful for some of us:
Multithreading example using a minimal context switcher

GrumpyOldPizza
Wed Jun 29, 2016 3:49 pm
mrburnette wrote:Interesting paper:

RTOS analysis for microcontrollers-Warning PDF=45KB

For systems comprising 16 or more tasks, the Non-
Preemption Group concept, combined with integrated
priority allocation and schedulability analysis results in
a reduction in the number of preemption levels re-
quired by a factor of 4 or more

Ray


Ollie
Wed Jun 29, 2016 6:36 pm
Protothreads is already over 10 years old invention to allow the appearance of multitasking without the complexities related to stack management and preemption. The preemption creates so many indirect system issues that in practice the product quality goes down.

Almost for 10 years there has been Contiki OS that is based on protothreads. It is widely used in communication systems where the time management is essential with minimum waiting times and large number of timeout conditions.

I was involved in realtime OS development for communication and industrial control over 30 years ago and based on my observations over the past 40 years, my recommendation is a solution that reduces the complexity of the total system.

Cheers, Ollie


GrumpyOldPizza
Thu Jun 30, 2016 9:53 pm
Ollie wrote:Almost for 10 years there has been Contiki OS that is based on protothreads. It is widely used in communication systems where the time management is essential with minimum waiting times and large number of timeout conditions.

mrburnette
Thu Jun 30, 2016 11:50 pm
GrumpyOldPizza wrote:
<…<However typical ARM MCUs have moved to 16kB SRAM, where real preemptive multitasking is less of a problem, and the advantage of proper software layering is more important.

martinayotte
Fri Jul 01, 2016 2:45 am
… and with F4s, which has a lot more SRAM, many task’s sub-stacks can be added …

Ollie
Fri Jul 01, 2016 5:54 pm
If in one end we have Arduino with full blocking and without any support for multitasking and in the other end we have an industrial strength RTOS with the related processes for requirements management, quality assurance, source code management, defect tracking, and similar disciplines, what would be a sweet spot for the audience in this forum?

My reading is that it is very close to plain Arduino without any kind of OS. What are the RTOS systems that you are using and can you recommend some of them to this audience?

Cheers, Ollie


ddrown
Sat Jul 02, 2016 1:09 am
Ollie wrote:If in one end we have Arduino with full blocking and without any support for multitasking and in the other end we have an industrial strength RTOS with the related processes for requirements management, quality assurance, source code management, defect tracking, and similar disciplines, what would be a sweet spot for the audience in this forum?

My reading is that it is very close to plain Arduino without any kind of OS. What are the RTOS systems that you are using and can you recommend some of them to this audience?

Cheers, Ollie


Pito
Sun Jul 03, 2016 6:57 pm
I did with NilRtos on Arduino and was happy with it. Ran about 20 tasks, NilFifo with sdcard writing data. Unfortunately BillG (he did the port to avr) is not keen on porting it to stm32duino.. http://forum.arduino.cc/index.php?topic … msg1092515

Leave a Reply

Your email address will not be published. Required fields are marked *