 #include "Cosa/Trace.hh"
 #include "Cosa/IOStream/Driver/UART.hh"
 
-// Example calibration values for internal clocks
-// 1. Duemilanove Clone (Funduino 2012 May)
+// -------------------------------------------------------------------
+// Calibration values for some of the boards that are used in the Cosa
+// build and tests. Note that there are variations between individual
+// boards due to factory calibration and the quality of the crystal
+// (+- 50 ppm) or ceramic resonator (+-.5%) and PCB layout.
+// -------------------------------------------------------------------
+// #define BOARD_INFO "Anarduino Miniwireless"
+// #define RTC_CALIBRATION_MS 0
+// #define WATCHDOG_CALIBRATION_MS -66
+// -------------------------------------------------------------------
+// #define BOARD_INFO "Duemilanove Clone (Funduino 2012 May)"
 // #define RTC_CALIBRATION_MS 0
 // #define WATCHDOG_CALIBRATION_MS -12
-// 2. Leonardo (Made in Italy)
+// -------------------------------------------------------------------
+// #define BOARD_INO "Leonardo (Made in Italy)"
+// #define RTC_CALIBRATION_MS 0
+// #define WATCHDOG_CALIBRATION_MS -95
+// -------------------------------------------------------------------
+// #define BOARD_INO "Lilypad Clone (GEtech)"
+// #define RTC_CALIBRATION_MS -1
+// #define WATCHDOG_CALIBRATION_MS -140
+// -------------------------------------------------------------------
+// #define BOARD_INFO "Mega 2560 Clone"
 // #define RTC_CALIBRATION_MS -2
-// #define WATCHDOG_CALIBRATION_MS -98
-// 3. Mega 2560 Clone
-// #define RTC_CALIBRATION_MS -1
+// #define WATCHDOG_CALIBRATION_MS -63
+// -------------------------------------------------------------------
+// #define BOARD_INFO "Mega 2560 Clone (Funduino)"
+// #define RTC_CALIBRATION_MS 0
 // #define WATCHDOG_CALIBRATION_MS -108
-// 4. Mega 2560 Clone (Funduino)
-// #define RTC_CALIBRATION_MS 0
-// #define WATCHDOG_CALIBRATION_MS -110
-// 5. Nano Clone (DCCduino)
+// -------------------------------------------------------------------
+// #define BOARD_INFO "Microduino Core"
+// #define RTC_CALIBRATION_MS 0
+// #define WATCHDOG_CALIBRATION_MS -69
+// -------------------------------------------------------------------
+// #define BOARD_INFO "Microduino Core+"
+// #define RTC_CALIBRATION_MS 1
+// #define WATCHDOG_CALIBRATION_MS -112
+// -------------------------------------------------------------------
+// #define BOARD_INFO "Microduino Core32U4"
+// #define RTC_CALIBRATION_MS 0
+// #define WATCHDOG_CALIBRATION_MS -8
+// -------------------------------------------------------------------
+// #define BOARD_INFO "Moteino"
+// #define RTC_CALIBRATION_MS 0
+// #define WATCHDOG_CALIBRATION_MS -118
+// -------------------------------------------------------------------
+// #define BOARD_INFO "Nano Clone (DCCduino)"
 // #define RTC_CALIBRATION_MS 0
 // #define WATCHDOG_CALIBRATION_MS -24
-// 6. Pro-Mini Clone (white reset button)
+// -------------------------------------------------------------------
+// #define BOARD_INFO "Pro-Micro Clone"
+// #define RTC_CALIBRATION_MS 0
+// #define WATCHDOG_CALIBRATION_MS 0
+// -------------------------------------------------------------------
+// #define BOARD_INFO "Pro-Mini Clone (Tinyos, 3.3V/8M)"
+// #define RTC_CALIBRATION_MS -2
+// #define WATCHDOG_CALIBRATION_MS -61
+// -------------------------------------------------------------------
+// #define BOARD_INFO "Pro-Mini Clone (white reset button)"
 // #define RTC_CALIBRATION_MS 0
 // #define WATCHDOG_CALIBRATION_MS 26
-// 7. Pro-Mini Clone (Deek Robot, red reset button)
+// -------------------------------------------------------------------
+// #define BOARD_INFO "Pro-Mini Clone (Deek Robot, red reset button)"
 // #define RTC_CALIBRATION_MS 0
 // #define WATCHDOG_CALIBRATION_MS -1
-// 8. Uno R3 Clone (GEtech)
+// -------------------------------------------------------------------
+// #define BOARD_INFO "Pro-Mini Clone (Deek Robot, 10 top pins)"
+// #define RTC_CALIBRATION_MS 0
+// #define WATCHDOG_CALIBRATION_MS 0
+// -------------------------------------------------------------------
+// #define BOARD_INFO "Uno R3 Clone (GEtech)"
 // #define RTC_CALIBRATION_MS 0
 // #define WATCHDOG_CALIBRATION_MS -112
-// 9. Uno R3 Clone (VISduino)
-// #define RTC_CALIBRATION_MS 0
-// #define WATCHDOG_CALIBRATION_MS -24
-// 10. Anarduino Miniwireless
-#define RTC_CALIBRATION_MS 0
-#define WATCHDOG_CALIBRATION_MS -66
-// 11. Your Arduino
-// #define RTC_CALIBRATION_MS 0
-// #define WATCHDOG_CALIBRATION_MS 0
-
-// Wall-clocks
+// -------------------------------------------------------------------
+// #define BOARD_INFO "Uno R3 Clone (VISduino)"
+// #define RTC_CALIBRATION_MS 0
+// #define WATCHDOG_CALIBRATION_MS -22
+// -------------------------------------------------------------------
+// #define BOARD_INFO "Wildfire"
+// #define RTC_CALIBRATION_MS 0
+// #define WATCHDOG_CALIBRATION_MS -122
+// -------------------------------------------------------------------
+
+// Wall-clocks; Square Wave from external RTC, internal RTC and
+// Watchdog based seconds level clocks
+#if defined(ARDUINO_MEGA)					\
+  || defined(ARDUINO_PRO_MICRO)
+Alarm::Clock clock(Board::EXT3);
+#elif defined(ARDUINO_LEONARDO)	   				\
+  || defined(MICRODUINO_CORE_PLUS)				\
+  || defined(MICRODUINO_CORE32U4)
+Alarm::Clock clock(Board::EXT2);
+#else
 Alarm::Clock clock(Board::EXT1);
+#endif
 RTC::Clock wall;
 Watchdog::Clock bark;
 

  trace.begin(&uart, PSTR("CosaClockCalibration: started"));

  // Print calibration
#if defined(RTC_CALIBRATION_MS)
  trace << PSTR("RTC:calibration: ") << RTC_CALIBRATION_MS << endl;
#endif
#if defined(WATCHDOG_CALIBRATION_MS)
  trace << PSTR("Watchdog:calibration: ") << WATCHDOG_CALIBRATION_MS << endl;
#endif

  // Start the watchdog and internal real-time clock
  Watchdog::begin();
  RTC::begin();

  // Set calibration (from error measurement)
#if defined(RTC_CALIBRATION_MS)

  OutputPin m_pin;
};

// Pulse generators from the different clocks (logic analyzer channel colors)
Pulse black(&clock, 1, Board::D7);
Pulse brown(&wall, 1, Board::D8);
Pulse red(&bark, 1, Board::D9);

void setup()
{
