Shop OBEX P1 Docs P2 Docs Learn Events
Compiling C++ code - Arduino Code — Parallax Forums

Compiling C++ code - Arduino Code

KyeKye Posts: 2,200
edited 2012-03-08 10:27 in Propeller 1
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,

Comments

  • Ken GraceyKen Gracey Posts: 7,400
    edited 2012-03-07 16:17
    You have our support and appreciation to do this project.

    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
  • KyeKye Posts: 2,200
    edited 2012-03-07 16:40
    Yes, I will be using the Prop GCC library. I will also be basically testing it extensively. I don't think I will need PropBOE stuff. I'm only going to port everything here: http://arduino.cc/en/Reference/HomePage and here: http://arduino.cc/en/Reference/Libraries. I don't have plans to rewrite everything either. But I will go through all the code and make sure it works. Some of the more complex libraries may not be ported quickly... (Ethernet Stuff).

    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.
  • denominatordenominator Posts: 242
    edited 2012-03-07 16:59
    Kye wrote: »
    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.

    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.
  • Martin HodgeMartin Hodge Posts: 1,246
    edited 2012-03-07 17:13
    Kye, I can provide you with whatever hardware you need. PM me!
  • jazzedjazzed Posts: 11,803
    edited 2012-03-07 17:16
    You have my full support.

    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
  • KyeKye Posts: 2,200
    edited 2012-03-07 17:25
    Mmm, I'm thinking mainly about the static inaction.

    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.
  • mindrobotsmindrobots Posts: 6,506
    edited 2012-03-07 17:26
    I can help if you need any unskilled labor (dotting i's, crossing t's, documenting). I have Ardiuno's, an ASC and a variety of Propellers....and mad Attention Deficit skillz!
  • KyeKye Posts: 2,200
    edited 2012-03-07 17:28
    I'll release stuff as I go to the PropGCC website. It can then be downloaded there and tested.
  • KyeKye Posts: 2,200
    edited 2012-03-08 10:27
    Hey all, so I just looked through the Arduino environment and it will be pretty straight forward to modify the Arduino environment to support the propeller chip. In fact, you will get access to the whole Arduino environment and it will feel exactly like you are programming an Arduino.

    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,
Sign In or Register to comment.