Cosa: An Object-Oriented Platform for Arduino programming

It is interesting how much know-how and energy do spend/invest people into retro-computing stuff (when talking 8-bitters) :slight_smile:
PS: PIC32MX250F128B costs the same as the atmega328p and less than the atmega1284p..

fat16lib:

Wow! Thats something I only dream of ;-). There is a lot of design in Cosa to use PROGMEM when ever possible and cut down on SRAM usage. With 16K I could put in a real RTOS with processes :wink:

You can really speed up pin I/O using a template class. I just posted a library that does writes in two cycles or 0.125 usec on an Uno. That library is at the above location.

I looked at your library recently and found that it uses much the same techniques as in Cosa and Jeelab. The current Arduino/Wiring style can be improved a lot with regards to speed and abstraction. Using C++ is a way forward.

The more important issues are abstracting and structuring the code base so that drivers, libraries, etc, can be added in a methodological fashion. Also I see a need to abstract IO functionality so that devices can be extended, replaced, etc. The IOStream/Canvas and IOBuffer classes in Cosa help a lot with this.

It would be nice to have a device driver framework for Arduino that allows a component view of both hardware modules/shields and software. Cosa is a small step in this direction. 1-Wire, I2C, SPI, etc, needs an abstraction layer and protocol generation so that integration becomes as easy as build in Arduino today. The research done in the d-tools project is an excellent starting point but we need to look at platform support for communicating systems; e.g. application build onto multiple boards, processors, etc, communicating over wire or wireless.

Hardware wise Arduino is a great contribution to getting cheap hardware for schools, university, prototyping and hobby projects. Software wise we have a lot more to do. Much has been done but additional structuring and refactoring is needed for the next quantum leap. Arduino/Wiring is great for beginners but it has some obstacles when it comes to scaling to larger projects. And 32-bits processors are not the answer even if they remove some of the resource limitations (memory, etc).

I think that there is a fair number of professionals with many years of experience of software design and implementation out there/here using Arduino for fun which could and should contribute in this process.

Cheers!

pito:
It is interesting how much know-how and energy do spend/invest people into retro-computing stuff (when talking 8-bitters) :slight_smile:
PS: PIC32MX250F128B costs the same as the atmega328p and less than the atmega1284p..

A chip alone does not a board make. I think you underestimate the fun of making a '8 bitter' do what one can make them do. It's a hobby dude. We don't do it to try and impress the ladies. :wink:

Lefty

The more important issues are abstracting and structuring the code base so that drivers, libraries, etc, can be added in a methodological fashion. Also I see a need to abstract IO functionality so that devices can be extended, replaced, etc. The IOStream/Canvas and IOBuffer classes in Cosa help a lot with this.

This won't happen as long as the Arduino company controls the IDE and you fit your stuff into that environment. The average user just won't use Cosa since what they get from Arduino is good enough for hobby use.

I was involved with BSD Unix at Berkeley. The goal of BSD was to replace AT&T Unix, not fit in. The open source Unix evolved into Linux and is the base for OS X and Android.

Open source Uinx happened because AT&T was impossible to deal with. The Arduino company provides a product hobbyists like or at least live with.

I have ported popular open source RTOSs to Arduino but don't see much interest.

I just accept Arduino and build little add-on libraries that may be useful to users.

I do think serious embedded systems need a preemptive priority scheduler. The research in the 1970s on scheduling with the Liu and Layland theorem on rate monotonic scheduling and Horn’s algorithm (earliest deadline first) are key to modern tools and design.

Object-oriented technology is nice but is hardly mentioned in modern courses on embedded system software like this http://chess.eecs.berkeley.edu/eecs149/.

Models of computation with time and concurrency are much more important than object-oriented software methods.

fat16lib:
This won't happen as long as the Arduino company controls the IDE and you fit your stuff into that environment. The average user just won't use Cosa since what they get from Arduino is good enough for hobby use.

I was involved with BSD Unix at Berkeley. The goal of BSD was to replace AT&T Unix, not fit in. The open source Unix evolved into Linux and is the base for OS X and Android.

Open source Uinx happened because AT&T was impossible to deal with. The Arduino company provides a product hobbyists like or at least live with.

I have ported popular open source RTOSs to Arduino but don't see much interest.

I just accept Arduino and build little add-on libraries that may be useful to users.

Supporting a movement like Arduino is not an easy task as the main focus is not programming and the majority of users (and founders) are not programmers. But all this risks graining to a halt when scale starts to play in. The lack of structure will need to be addressed sooner or later and the foundation needs to be production quality; rock solid.

Using a Due with current Ardunio software should be compared to, for instance, using a RaspberryPI. Due gives for the average user just more memory, speed and ports. Trying to integrate different libraries is near impossible as the problem was not so much the lack of memory as the lack of structure. I think that the Mega has already shown this problem.

Professionals don't really use the Arduino IDE. It is basically a toy. A nice toy - but still a toy. The thing is to work around it and replace it in increments. Show the alternatives - slowly. Obviously Cosa can be built without any of the Arduino IDE/library/etc. The only essential part is AVR tools with GCC etc. GNU emacs and make works just fine as an IDE replacement :wink:

I think it is important to show possible steps forward with regard to structuring and using the full power of the programming language C++ for small scale embedded systems. I intend to include a Forth-like virtual machine (working name Avanti) in Cosa. This would gives direct access to the Arduino hardware without a compiler when needed and the possibility to add Domain Specific Languages for teaching, rapid prototyping, etc. The concurrency.cc project is a good inspiration in this regard.

If you think OOP is too larger step for the Arduino community then RTOS is "from here to eternity" :wink:

BW great comments and insights!

Cheers.

I don't use Arduino boards or the IDE for serious projects. There are way better hardware and software options.

Using a Due with current Ardunio software should be compared to for instance using a RaspberryPI

For my use, RaspberryPI is a dud, mine is in a box in the garage.

Here is a board I like STM32-E407 - Open Source Hardware Board You get a 390ns context switch with STM32F4 and ChibiOS/RT.

I like systems like ChibiOS/RT with a HAL and support for tons of boards/processors.

If you think OOP is too larger step for the Arduino community then RTOS is "from here to eternity" :wink:

I agree, object-oriented threads are an ugly answer to real-time systems.

Current embedded systems research is looking for a better programming model. Progress is really slow.

The object-oriented model is good for data processing and not bad for GUI programming. Fortunately tablets/phones have an very smart component, a human, that puts up with all the warts and hiccups.

I have worked on control systems for the world's largest science experiments and object-oriented techniques just haven't delivered. 20 years ago I was an extreme fan of OO.

I don't use Arduino boards or the IDE for serious projects.

Hear, hear!

Smacks of elitism, but I would assume you wouldn't mind if others do their serious projects on same. :wink:

Lefty

retrolefty:

I don't use Arduino boards or the IDE for serious projects.

Hear, hear!

Smacks of elitism, but I would assume you wouldn't mind if others do their serious projects on same. :wink:

Hum, I guess "serious projects" means industry/commercial prototyping and not "your serious hobby projects". We are a few that get to work with embedded systems and use a lot of alternative software and hardware. I hope that whatever the scope of the project we have a set of tools to choice from. And we do it for fun and learn something new in the process.

It is important that young talented arduino users will grow - therefore ie. such TLAs like RTOS, OOP etc. shall attract them.. Veterans, like me, love 8bitters, especially when more powerful than Block II AGC.. :wink:

Lefty,

Let me explain serious from my point of view.

I spent most of my career as an architect for large embedded systems. I did some of the initial architecture for one of the LHC experiments that discovered the Higs Boson at CERN.

Systems like this are implemented with a certified reliable RTOS. LHC used LynxOS.

The LynxOS-178 RTOS is the first and only hard real-time DO-178B level A operating system to offer the interoperability benefits of POSIX® with support for the ARINC 653 APplication EXecutive (APEX).

This is professional level serious.

I have often used VxWorks, the system used in Mar Landers. Two of my former colleagues founded Wind River Systems and developed this RTOS. This is also a professional level serious RTOS.

I am now retired but do a little commercial development. I just don't find Arduino hardware/software reliable enough for this use. FreeRTOS and ChibiOS/RT fit this level of seriousness, they have support for commercial use.

I love playing with small programs on Arduino. I am a frustrated programmer want-to-be. Management forbid me from implementing any of my designs since a large programming staff was hired to do that. This is hobby fun level of seriousness and Arduino is great.

So the Arduino millisecond clock ticks every 1024 microseconds then does two ticks every 41-42 milliseconds to catchup. This is a hobby level system.

fat16lib:
Lefty,

Let me explain serious from my point of view.

I spent most of my career as an architect for large embedded systems. I did some of the initial architecture for one of the LHC experiments that discovered the Higs Boson at CERN.

Systems like this are implemented with a certified reliable RTOS. LHC used LynxOS.

The LynxOS-178 RTOS is the first and only hard real-time DO-178B level A operating system to offer the interoperability benefits of POSIX® with support for the ARINC 653 APplication EXecutive (APEX).

This is professional level serious.

I have often used VxWorks, the system used in Mar Landers. Two of my former colleagues founded Wind River Systems and developed this RTOS. This is also a professional level serious RTOS.

I am now retired but do a little commercial development. I just don't find Arduino hardware/software reliable enough for this use. FreeRTOS and ChibiOS/RT fit this level of seriousness, they have support for commercial use.

I love playing with small programs on Arduino. I am a frustrated programmer want-to-be. Management forbid me from implementing any of my designs since a large programming staff was hired to do that. This is hobby fun level of seriousness and Arduino is great.

So the Arduino millisecond clock ticks every 1024 microseconds then does two ticks every 41-42 milliseconds to catchup. This is a hobby level system.

I have no real issues of the subject and content that you and others in this thread have posted, but rather the tone and impression of the specific comments I listed. The arduino platform was well designed and build for the users it was aimed at, non technical users. It's also a continuously changing and improving platform that is evolving as people contribute more and more to it. The vast popularity of the platform and the huge membership of this forum kind of validates that there exists such a viable user base.

And there are many members here that come from professional background in software and/or hardware that like to contribute knowledge, share library contributions (as you certainly have), and otherwise encourage the less experienced members.

It just rubbed me (and maybe only me) the wrong way to read:

I don't use Arduino boards or the IDE for serious projects.

Followed with a supporting:

Hear, hear!

I know your contributions to the arduino platform do not reflect a person with an elitism attitude towards arduino projects or members using the platform, so don't take my comments as personal criticism of you, but rather just criticism of the comments that were posted.

Peace
Lefty

You may enhance your Cosa mcu collection with atmega32 (same pin layout as the 1284p, bootloader works, the core and variant of the mighty1284p works under 1.5.2.). The major diff is it has got only 4 PWM and single UART - maybe the UART setting needs a fix.

// MIGHTY ATMEL ATMEGA32
//                       +---\/---+
//           (D 0) PB0  1|        |40  PA0 (AI 0 / D24)
//           (D 1) PB1  2|        |39  PA1 (AI 1 / D25)
//      INT2 (D 2) PB2  3|        |38  PA2 (AI 2 / D26)
//       PWM (D 3) PB3  4|        |37  PA3 (AI 3 / D27)
//        SS (D 4) PB4  5|        |36  PA4 (AI 4 / D28)
//      MOSI (D 5) PB5  6|        |35  PA5 (AI 5 / D29)
//      MISO (D 6) PB6  7|        |34  PA6 (AI 6 / D30)
//       SCK (D 7) PB7  8|        |33  PA7 (AI 7 / D31)
//                 RST  9|        |32  AREF
//                 VCC 10|        |31  GND 
//                 GND 11|        |30  AVCC
//               XTAL2 12|        |29  PC7 (D 23)
//               XTAL1 13|        |28  PC6 (D 22)
//      RxD (D 8)  PD0 14|        |27  PC5 (D 21) TDI
//      TxD (D 9)  PD1 15|        |26  PC4 (D 20) TDO
//     INT0 (D 10) PD2 16|        |25  PC3 (D 19) TMS
//     INT1 (D 11) PD3 17|        |24  PC2 (D 18) TCK
//      PWM (D 12) PD4 18|        |23  PC1 (D 17) SDA
//      PWM (D 13) PD5 19|        |22  PC0 (D 16) SCL
//          (D 14) PD6 20|        |21  PD7 (D 15) PWM
//                       +--------+
//

pito:
You may enhance your Cosa mcu collection with atmega32 (same pin layout as the 1284p, bootloader works, the core and variant of the mighty1284p works under 1.5.2.).

I will see if I get the time for this later this week. Dont like the idea of doing too many modifications I cant run through the tests. Thanks for the schematics. Will need to read up on the spec as well.
Cheers.

A new blog posting is now available with some details on how the Pin classes work in Cosa.

Cheers!

I spent most of my career as an architect for large embedded systems. I did some of the initial architecture for one of the LHC experiments that discovered the Higs Boson at CERN.

Systems like this are implemented with a certified reliable RTOS. LHC used LynxOS.

Just to present a counter-argument, I spent most of my career as a developer at cisco Systems, which helped create The Internet As We Know It Today. A cisco router is a fairly large embedded system that uses a home-built OS that is not certified, not realtime, and not particularly (certainly not inherently) reliable. I remember way back when BBN announced that they had gotten their fancy multicore "butterfly" router to reliably switch packets within 1ms. At the time, cisco routers were switching most of the packets in about 12 us... (but we couldn't do ALL of them within 1ms.)

The other interesting part involved cisco's experiments (and products) that WERE/ARE based on real-time kernels. It turns out that effectively using a modern RT kernel is a pretty complex undertaking, and it's really easy to shoot yourself in the foot...

I am not sure what your point is?

Just to present a counter-argument,

Yes, Cisco is a great company and we have used many of their products in physics. Some of the network research done at LBL was used by Cisco. One of my colleagues, Van Jacobson, was Chief Scientist at Cisco for a few years.

It turns out that effectively using a modern RT kernel is a pretty complex undertaking, and it's really easy to shoot yourself in the foot...

Today students in courses like "Introduction to Embedded Systems" http://chess.eecs.berkeley.edu/eecs149/ learn to use an RTOS in the first weeks.

I don't understand why hobbyists can't use an RTOS as a useful tool. Hobbyists design circuits and pcbs.

I agree that hobbyists won't build systems like LHC detectors, projects like LHC also design there own semiconductor parts to achieve performance.

The detector generates large amounts of raw data: about 25 megabytes per event (raw; zero suppression reduces this to 1.6 MB), multiplied by 40 million beam crossings per second in the center of the detector. This produces a total of 1 petabyte of raw data per second.

There are three trigger levels. The first is based in electronics on the detector while the other two run primarily on a large computer cluster near the detector. The first-level trigger selects about 100,000 events per second. After the third-level trigger has been applied, a few hundreds of events remain to be stored for further analysis. About 15 petabytes of data per year are saved for further analysis.

Systems like this are implemented with a certified reliable RTOS. LHC used LynxOS.

I was talking about serious professionally designed systems, not hobby projects.

Today students in courses like "Introduction to Embedded Systems" http://chess.eecs.berkeley.edu/eecs149/ learn to use an RTOS in the first weeks.

Is that a required class for either EE or CS degree programs? It doesn't seem to be. Which means that you can graduate with one of the most prestigious engineering degrees in the country without having been taught how to use an RTOS...

My point is that an RT operating system is NOT a requirement for a serious commercial embedded system. A useful tool, probably. Most people will probably get more out of multitasking than they do out of "real time", but if a RTOS is the easiest way to mutitasking, that's fine...

My point is that an RT operating system is NOT a requirement for a serious commercial embedded system.

Yes, but you old timers are retiring. At one time no computer ran an OS. No embedded system used a compiled language.

Mentor Graphics Nucleus RTOS (Real-time Operating System), Deployed on over 3 Billion Devices.

VxWorks and LynxOS are also in billions of devices.

westfw,

Please don't write-off courses like UCB EECS149, hundreds of universities are developing this type of course and thousands of engineers around the world are taking these courses.

A large effort and substantial funding is going into improving engineering education for what we call embedded systems. NSF funds this area under "Cyber-Physical Systems". Google for this phrase to see the level of activity.

Remember, you will be sharing the road with autonomous vehicles these engineers design. These won't be just any old vehicles, NSF wants:

Automation for Truck Platooning.

A short update: I recently added an object-oriented refactoring of the VirtualWire library to Cosa, and extended it with a Manchester Phase Encoder (MPE) as an alternative codec.

https://github.com/mikaelpatel/Cosa/blob/master/Cosa/VWI.hh
https://github.com/mikaelpatel/Cosa/blob/master/Cosa/MPE.hh

Please see the example code for VWI and MPE.

There is also an IOStream driver for the Virtual Wire Interface (VWI) which allows simple binding of an iostream to the wireless connection and printouts over the connections. Note that there is no retransmission so printouts may be lost. Retransmission has to be implemented on the next level (ie protocol stack or message protocol). Sending messages over VWI and MPE is a bit like UDP but without addressing.

https://github.com/mikaelpatel/Cosa/blob/master/Cosa/IOStream/Driver/VWIO.hh

Have fun().

Hi Kowalski,
I cant resist saying how your work is great with Cosa, lot of work and lot of good ideas in there to make the lib powerfull and exhaustive !
may I suggest 3 things for it success or adoption :

  • make it modular : dont force any body, by its structure, to use a module they dont need. for example, I could use iemdiately Pins and event, but I m not interested by other HAL around SPI or TWI. of course youd say it is possible, but we have to make this "choice" and interoperatibility with Arduino.h as simple as possible. in that respect the config file from chibios is a potential idea here.
  • make sure you end up with a team of adopter/contributor to support the Cosa project. before starting using and deep diving with a new core we want to be sure it will be supported further
  • please prepare and organize so that the library can be used one day or another with ARM boards like Teensy3 and Due ! should put plenty of #ifdef arm/AVR, doing this during coding will also force you to find a data model and a code structure which is not closed to the ARM

amazing job again