Compiling C++ code - Arduino Code
Kye
Posts: 2,200
So, I'm thinking about taking on the project of porting all of the Arduino core libraries to the Propeller Chip.
That said,
I need to be able to compile C++ code and be able to declare new objects and do things with them.
I saw a number of post that said that the new and delete functionality took up too much space to use. My question though, is how is this done using the Arduino then? When I compile code for the Arduino I do not see all of my memory being eaten up by declaring an object.
---
My goal is to make the library as compatible to Arduino code as I can get. I know there will be some things that I will not be able to replicate perfectly (interrupts), but I need to have the basic C++ functionality working so the library can be seamlessly used by already written Arduino code out in the wild that does not touch AVR specific stuff.
---
What would I need to do to make this happen? I will start working on this project in late May.
Thanks,
That said,
I need to be able to compile C++ code and be able to declare new objects and do things with them.
I saw a number of post that said that the new and delete functionality took up too much space to use. My question though, is how is this done using the Arduino then? When I compile code for the Arduino I do not see all of my memory being eaten up by declaring an object.
---
My goal is to make the library as compatible to Arduino code as I can get. I know there will be some things that I will not be able to replicate perfectly (interrupts), but I need to have the basic C++ functionality working so the library can be seamlessly used by already written Arduino code out in the wild that does not touch AVR specific stuff.
---
What would I need to do to make this happen? I will start working on this project in late May.
Thanks,
Comments
I assume you'd be building upon the top of our C library? David Betz is producing C examples for the PropBOE and our key sensors. Would these be of use for you to build upon? They're presently not posted anywhere (I think) but we aim to consolidate these examples and make them available for PropBOE users.
Ken Gracey
The goal is to have complete Arduino functionality. I don't think it will be that hard either since I will just be porting the code. This means I can just use the Arduino documentation to document the library with only a few minor changes and also the Arduino examples to test and provided examples for the code. I'm also thinking about providing a board design for the library to standardize which pins connect to what.
I think it's going to be quite doable as long as I can get the C++ stuff working with help from Jazzed and the rest of the PropGCC team.
new and delete do not take up too much space to use. That being said, the caveat previously expressed was that in any embedded system (Arduino included) heap should be very carefully managed because of the limited memory and the potential for fragmenting the heap. The typical way you use C++ objects in an embedded system is to declare them as static/global variables; that way you know in advance that all your needed objects fit in memory. You could also use stack variables to work around any possibility of memory fragmentation, but even so the use of the stack needs to be carefully monitored to make sure you don't run out of stack space.
You can find a wiki page at http://code.google.com/p/propgcc/wiki/PropGccTightMemory that describes how to use C++ in PropGCC's in LMM programs.
From all I can tell Arduino probably doesn't use new/delete.
Such C++ programs can be compiled with straight GCC.
Remember that most AVR chips on Arduino are 16KB or 32KB flash and teeny 2KB or less data SRAM.
Also Arduino has a Wiring layer which hides things. There is a pointer to their repository on the site.
Ted's (denominator) wiki pages are all certainly worth "close" reading.
I'm all ears when you need me.
Thanks,
--Steve
This is where they (outside of a function) declare the object type and then an instance name for that object type.
I don't think this needs the heap. But, I don't really know C++ all that well. I am taking on this project to learn a bit more (I don't expect to learn a lot... but a bit is nice).
---
I need to have code compatibility, however. I'm asking these questions now to see if the path I wish to travel is folly.
To do this I will need to build a special version of their editor which supports command line options and different tools. Once this is done, I can just add the propgcc distribution to the Arduino environment and everything will be good to go. I think it will also be possible to have the environment keep support for the main AVR boards at the same time. It will be a little tricky though to resolve AVR and Prop library conflicts. The Arduino core libraries do not have any indirection built into their file structure. This means I can either create some UGLY #ifdef files (I do not want to do this). Or I need will need to rearrange how files are stored in the Arduino environment.
I will be trying to do as little work as possible to complete the port as I would not like to have it consume my life. I would like to be able to reuse all the Arduino documentation.
Anyways, I won't start working on this for a while.
Thanks,