Pages: [1] 2 3 4   Go Down
Author Topic: Multithreading on Arduino?  (Read 10887 times)
0 Members and 1 Guest are viewing this topic.
Athens, Vienna
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Embedded Software Specialist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

On the old forum I came across DruidOS (FreeRTOS+Arduino) http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1256745982/180 which seems to be a bit outdated and orphaned, although it looks like a very nice solution to bring multithreading to Arduino.

With the upcoming much more powerful Arduino boards (ARM and friends) we will be able to tackle more complex problems and all the great Arduino libraries plus a RTOS might be helpful. Also if we would have multithreading in mind from the beginning the libraries could be designed accordingly from the beginning and there would be no need to add somehow multithreading support to them as an afterthought like it is right now.

Is there going to be any Arduino officially supported multithreading solution?

Is someone interested in maintaining DruidOS?

Please advise.

Regards,

Robert
Logged

--
Robert Berger
Embedded Software Specialist

Reliable Embedded Systems
Consulting Training Engineering
URL: http://www.reliableembeddedsy

'round the world...
Offline Offline
Faraday Member
**
Karma: 42
Posts: 3267
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't think that having an RTOS on a 8 bit chip is worth the overhead. Plus, real multithreading is impossible in the normal Arduinos.

Having that on the new ARM platform however, could be a nice project.
Logged

Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2073
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Robert, very good point. This is what arduino lacks. Most probably because even today the mainstream here is the 328p. I do not understand why such chips like 1284p are still not taken into serious consideration. 16kB of ram is big enough for any rtos or a simple os. p.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 135
Posts: 6763
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
real multithreading is impossible in the normal Arduinos.
Why do you say that?  (it could be true, depending on your definition of "real multithreading", but...)

this recently showed up on the Developers mailing list:

Quote
The ThreadKit library [http://code.google.com/p/threadkit/] provides
simple, low-overhead, non-stack-based, cooperative multithreading on
Arduino and similar microcontroller systems.  I have released a
preliminary version of ThreadKit for the Arduino IDE under the MIT
License.  To demonstrate the library on the Arduino platform, the
project includes a two-voice music-playing program called Muser.
Logged

Athens, Vienna
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Embedded Software Specialist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@bubulindo:

I have an Arduino UNO and DruinOS, which is derived from FreeRTOS, running happily on it.

FreeRTOS is a real RTOS and supports 8 bit microcontrollers like 8051, AVR, PIC18. I just ported it to a 18lf45k22 just because people were telling me that this is not possible  smiley-wink

It certainly adds a few percent of overhead for those little machines, but I'm more after the concept of programming in threads compared to the superloop, as it is typical for the Arduino.

Projects are usually growing and having an RTOS just helps to break things into tasks and to add new tasks without seriously affecting the timing.

Hey I'm a geek and use a RTOS even on small microcontrollers smiley-wink

... but as bigger microcontrollers are getting cheaper and cheaper it's certainly a topic we should look into a bit to be ready to roll on future Arduino boards ...

Regards,

Robert
Logged

--
Robert Berger
Embedded Software Specialist

Reliable Embedded Systems
Consulting Training Engineering
URL: http://www.reliableembeddedsy

Athens, Vienna
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Embedded Software Specialist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@westfw

I don't know threadkit, but judging from what I can see from the sources it's very limited because it is a cooperative scheduler and not a preemptive one and lacks interprocess communication primitives like e.g. semaphores, mutexes and queues.

Regards,

Robert
Logged

--
Robert Berger
Embedded Software Specialist

Reliable Embedded Systems
Consulting Training Engineering
URL: http://www.reliableembeddedsy

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 135
Posts: 6763
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
limited because it is a cooperative scheduler and not a preemptive one
You can do a LOT of multitasking without preemption.  cisco and procket operating systems were both cooperative...  Sometimes preemption causes as many problems as it "solves."

Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2073
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

BTW, the biggest issue with rtos-es is the availability of drivers for ie. i2c, spi, uart, etc. Pushing few buttons and blinking few leds works nice, however when the drivers are needed the fun with rtoses stops..p.
Logged

Athens, Vienna
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Embedded Software Specialist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@pito:

You wrote: "the biggest issue with rtos-es is the availability of drivers for ie. i2c, spi, uart, etc".

Talking about Arduino. It's biggest strength is exactly what you see as the biggest issue with RTOS-es.

Hence my idea to combine both.

Wouldn't it be great to have a RTOS with an Arduino API or Arduino with a RTOS?

If this is something more people are interested in I believe it's doable and in order to minimize most of the troubles you have with drivers and RTOS-es it would be good to put hooks into the Arduino libraries from now on and not as an afterthought.

What I mean is, that we could create libraries where the shared resources are protected by macros, which expand to nothing when you don't use any RTOS and which expand to something when a RTOS is used. Also we could actually get a performance gain under certain circumstances by using a RTOS because there will be no need for polling and the CPU could be given to other tasks.

Anyhow these are just preliminary thoughts and we'll need more discussions and a careful design.

Regards,

Robert
Logged

--
Robert Berger
Embedded Software Specialist

Reliable Embedded Systems
Consulting Training Engineering
URL: http://www.reliableembeddedsy

0
Offline Offline
Edison Member
*
Karma: 64
Posts: 1639
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am sure that RTOS-es will be used on ARM Arduinos.  It would be nice if some thought was given to the core software so it would work well with the old style Arduino setup(), loop() or with an optional RTOS.

Leaflabs includes FreeRTOS as a library for their STM32 Arduino-like board.

Leaflabs has done a great job with their libmaple for the STM32 ARM processors.
Logged

Austin, TX
Offline Offline
Full Member
***
Karma: 0
Posts: 134
I make my own electricity.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

BTW, the biggest issue with rtos-es is the availability of drivers for ie. i2c, spi, uart, etc. Pushing few buttons and blinking few leds works nice, however when the drivers are needed the fun with rtoses stops..p.

I'm not sure why you say that -- the ATmega chips are very capable of doing all those things.  The bigger issue is that the open source / GPL libraries tend to be lower quality and/or functionality that commercial products.  For hobbyists who want to use an RTOS, they'll have to write their own or get the quality of the libraries up to true production quality.

The other big problem is that the ATmega chips are Harvard architecture processors (separate instruction and data spaces) and have very limited data segment sizes.  Even that can be resolved using some of the SRAM chips with an SPI interface -- adding massive amounts of SRAM to an Arduino is just a matter of allocating some digital pins and using those parts.
Logged

0
Offline Offline
Edison Member
*
Karma: 64
Posts: 1639
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Arduino is open source so why not use other open source software with Arduino.  There are several open source RTOS-es that work fine.  FreeRTOS is used in lots of hobby projects and runs on avr.

Adding SPI SRAM is not very effective.  avr SPI is very slow programed I/O.  You can do a lot with the ATmega 1284, 16 KB SRAM.

ARM Arduino boards will be a better solution for larger apps.
Logged

Austin, TX
Offline Offline
Full Member
***
Karma: 0
Posts: 134
I make my own electricity.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've been using and producing open source software for the better part of 25 years -- there's nothing wrong with using it, or producing it, but many open source projects suffer from abandonment or incomplete functionality even if they are being maintained.  The most recent example of that is when I went looking for a Modbus sketch and wound up writing my own because the one that's most commonly referenced here and in other Arduino fora is both incomplete and very broken.  Great for hobbyists, lousy for production-quality work.

The best advantage to using SPI SRAM isn't that it's fast (it can be), it's that it's huge.  With a very small number of I/O pins you can get access to an almost unlimited amount of SRAM, 32KB at a pop.  All the ATmega chips have all the pins needed to give you all the SRAM you can eat.
Logged

0
Offline Offline
Edison Member
*
Karma: 64
Posts: 1639
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Guess you were talking storage.  I can get about 830 KB/sec to external SRAM or 1200 ns/byte.  Internal SRAM has a 62.5 ns cycle time.  The limit for Arduino is mostly due to the max SPI rate of 8 MHz which is 1000 KB/sec.

For huge I like Dataflash.  A 8-pin SOIC with SPI interface can store up to 16 megbits of data and costs under $2.50 from DigiKey.

I started developing/using open source software over 40 years ago so understand its nature.

When I needed reliable I went with systems like VxWorks from Wind River Systems, a company founded by two of my friends.

Arduino is open source.  Look at the Arduino core and notice that it could never pass certification for use in a critical embedded system.  So why worry so much about the stuff you use with it?  You don't use Arduino hardware/software for serious critical applications.

What company do you buy your production-quality Arduino software from?

Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2073
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Robert: Hmm, frankly, I would say you cannot use the existing libraries (ie i2c, spi, uart, etc.) for an rtos easily - you need to rewrite those as you need none blocking ones, you need to control a concurrent access to them from several tasks/threads, etc. This is the issue - my understanding is all drivers need to be redone..
So, again - I am writing here about "rtos-capable drivers and libraries"..p.
« Last Edit: October 09, 2011, 05:36:24 pm by pito » Logged

Pages: [1] 2 3 4   Go Up
Jump to: