Documentation for Programmers?

I realize that I’m not the target audience for this, but…

I’m an experienced embedded C programmer, and I’m looking for documentation describing just how the arduino/wiring/processing environment differs from more conventional C development and runtime environments, and just how I should approach the whole thing as a programmer.

Does such a document exist?

have you checked the “hacking” part of the website? It may help you. Otherwise I think it is interesting to see how to answer you, since it may be useful for many others.

Can you a little more specific?

/d

Yes, this document http://www.arduino.cc/en/Hacking/BuildProcess answered about half of my questions. The other half has more to do with the runtime environment. I gather that the arduino core calls setup() and then repeatedly calls loop(). OK. How big is my stack? Is anything else initialized? Is “it” compatible with standard gcc library functions, or do some of those need to be avoided? What does the runtime do, or what can I get it to do, in between “loop()” invocations? Why this particular structure? I guess part of the idea is to simplify C/C++? What things can I count on having the environment do well for me, and what things must I revert to “real C” for? Are there C and/or C++ structures that must or should be avoided? If it’s so flexible, how come no one has written and arduino core for the Butterfly board? Um… that’ll do for now.

Take a look at the source code to the Arduino core - it’s in the lib/targets/arduino subdirectory of the Arduino application directory, or online at: http://svn.berlios.de/wsvn/arduino/trunk/targets/arduino/?rev=0&sc=0.

A few things are initialized: timer 0 to keep track of the timing needed for the millis() functions, and timers 0, 1 and 2 for PWM generation. The analog to digital converter is initialized and the prescaler set.

Basically, the only thing we do to the code is add an #include statement to the top of it, and automatically generate prototypes for your functions. I think there are a few things that don’t work because there’s parser that goes through the code and complains about certain constructs. However, you can create new tabs in a sketch (use the right pointing arrow at the upper right) that are straight .c, .cpp, or .h files (just give them a name with the appropriate extension). These will be passed straight to the compiler without modification.

It is compatible with standard gcc library functions. You can add any #include statements you like. The only trick is that since you can’t modify the command line arguments passed to the compiler or linker (we could support this, but there hasn’t been much demand for it), a few things don’t work: some of the math.h functions (e.g. sin) because of a bug in avr-gcc/avr-libc (that means you need an extra -lm argument) and printing of floating point numbers.

The runtime does nothing between calls to loop(), the code is literally for (;;) loop();. This structure comes from Processing, and was chosen to try to provide beginners with a slightly simpler framework (e.g. removing the need for an explicit main loop, so they don’t need to know the syntax of, say, a for-loop to write a program).

It’s not that flexible… porting the core libraries to a new platform requires going in and adding appropriate #ifdefs and the like. It’s not too hard, but I don’t think there’s been much interest from the community. I guess most people who decide they need to use a different board have been willing to just code in straight C. That said, it’d be great to support more hardware, so any contributions are welcome.