Quick answer to some of the questions:
Cosa has two implementations of millis() depending on resolution and if the user wants to take full advantage of Cosa's support for extreme low power mode. The first implementation is Watchdog::millis(). This implementation gives a resolution of max 16 ms. The advantage is that the Watchdog timer will continue to run when the MCU is put into power down sleep (uA level). The second and more accurate version is RTC::millis() which is closest to the Arduino millis() function. Both timers requires a call to begin() in setup.
#include "Cosa/RTC.hh"
inline uint32_t millis()
{
return (RTC::millis());
}
void setup() {
...
RTC::begin();
...
}
Cosa is fully object-oriented and pins are different classes; Pin, InputPin, OutputPin, IOPin, AnalogPin, etc. There is a very rich set of member functions to write and read the pin values. Also Cosa uses strong data typing so that pins are actually symbols. The mapping to Arduino is:
#include "Cosa/InputPin.hh"
#include "Cosa/OutputPin.hh"
#include "Cosa/AnalogPin.hh"
inline int digitalRead(Board::DigitalPin pin)
{
return (InputPin::read(pin));
}
inline void digitalWrite(Board::DigitalPin pin, uint8_t value)
{
OutputPin::write(pin, value);
}
inline int analogRead(Board::AnalogPin pin)
{
return (AnalogPin::sample(pin));
}
The normal way to use Cosa Pins is:
InputPin button(Board::D4);
OutputPin LED(Board::D5, 1);
The pin constructor does all the initialization of pin mode, pull-up, and start value if needed.
Both the object-orientation (classes) and the strong typing contribute to the X2-X10 higher performance than Arduino/Wiring. Please see the Benchmarks;
https://github.com/mikaelpatel/Cosa/tree/master/examples/Benchmarks. The compiler can do a much better job and it is actually possible to write a pin-toggle function that is done in a single instruction (clock cycle, 62.5 ns) and still have a very high level of abstraction.
BW: There is a high level IOStream class for trace which allow syslog style prorities and that adds a lot of information to trace points. Below is a snippet from a trace.
45:void setup():trace:free_memory() = 387
53:void loop():measure:one character (new-line):28 us
1
54:void loop():measure:one character:36 us
1
55:void loop():measure:one character string:44 us
https://github.com/mikaelpatel/Cosa/blob/master/examples/Benchmarks/CosaBenchmar... The source code that generated this looks like this:
void setup()
{
...
TRACE(free_memory());
...
}
void loop()
{
// Measure time to print character, string and number
MEASURE("one character (new-line):", 1) trace << endl;
MEASURE("one character:", 1) trace << '1' << endl;
MEASURE("one character string:", 1) trace << PSTR("1") << endl;
...
}
https://github.com/mikaelpatel/Cosa/blob/master/examples/Benchmarks/CosaBenchmar... Cheers!