From d05d83e84530ebedd32256fc8c98e057607d1602 Mon Sep 17 00:00:00 2001 From: udoklein Date: Tue, 31 Jan 2017 21:14:09 +0100 Subject: [PATCH] added library properties file, added version control macros, some minor cleanup --- dcf77.cpp | 2 +- dcf77.h | 106 +++++++++++------- .../Swiss_Army_Debug_Helper.ino | 24 +++- library.properties | 9 ++ 4 files changed, 99 insertions(+), 42 deletions(-) create mode 100644 library.properties diff --git a/dcf77.cpp b/dcf77.cpp index 2453ea3..2a257eb 100644 --- a/dcf77.cpp +++ b/dcf77.cpp @@ -1626,7 +1626,7 @@ namespace Internal { // DCF77_Frequency_Control } #if defined(_AVR_EEPROM_H_) - volatile boolean DCF77_Frequency_Control::data_pending = false; + volatile bool DCF77_Frequency_Control::data_pending = false; // ID constants to see if EEPROM has already something stored static const char ID_u = 'u'; diff --git a/dcf77.h b/dcf77.h index dbd1937..dccc81c 100644 --- a/dcf77.h +++ b/dcf77.h @@ -16,44 +16,21 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see http://www.gnu.org/licenses/ +#ifndef dcf77_h +#define dcf77_h -#define GCC_VERSION (__GNUC__ * 10000 \ - + __GNUC_MINOR__ * 100 \ - + __GNUC_PATCHLEVEL__) - -#define ERROR_MESSAGE(major, minor, patchlevel) compiler_version__GCC_ ## major ## _ ## minor ## _ ## patchlevel ## __ ; -#define OUTDATED_COMPILER_ERROR(major, minor, patchlevel) ERROR_MESSAGE(major, minor, patchlevel) - -#if GCC_VERSION < 40503 - // Arduino 1.0.0 - 1.0.6 come with an outdated version of avr-gcc. - // Arduino 1.5.8 comes with a ***much*** better avr-gcc. The library - // will compile but fail to execute properly if compiled with an - // outdated avr-gcc. So here we stop here if the compiler is outdated. - // - // You may find out your compiler version by executing 'avr-gcc --version' - - // Visit the compatibility section here: - // http://blog.blinkenlight.net/experiments/dcf77/dcf77-library/ - // for more details. - #error Outdated compiler version < 4.5.3 - #error Absolute minimum recommended version is avr-gcc 4.5.3. - #error Use 'avr-gcc --version' from the command line to verify your compiler version. - #error Arduino 1.0.0 - 1.0.6 ship with outdated compilers. - #error Arduino 1.5.8 (avr-gcc 4.8.1) and above are recommended. - - OUTDATED_COMPILER_ERROR(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) -#endif +#define DCF77_MAJOR_VERSION 3 +#define DCF77_MINOR_VERSION 1 +#define DCF77_PATCH_VERSION 4 -#ifndef dcf77_h -#define dcf77_h #include - #if defined(ARDUINO) #include "Arduino.h" #endif + struct Configuration { // The Configuration holds the configuration of the clock library. @@ -102,19 +79,19 @@ struct Configuration { // the constant(s) below are assumed to be configured by the user of the library - static const boolean want_high_phase_lock_resolution = true; - //const boolean want_high_phase_lock_resolution = false; + static const bool want_high_phase_lock_resolution = true; + //const bool want_high_phase_lock_resolution = false; // end of configuration section, the stuff below // will compute the implications of the desired configuration, // ready for the compiler to consume #if defined(__arm__) - static const boolean has_lots_of_memory = true; + static const bool has_lots_of_memory = true; #else - static const boolean has_lots_of_memory = false; + static const bool has_lots_of_memory = false; #endif - static const boolean high_phase_lock_resolution = want_high_phase_lock_resolution && + static const bool high_phase_lock_resolution = want_high_phase_lock_resolution && has_lots_of_memory; enum ticks_per_second_t : uint16_t { centi_seconds = 100, milli_seconds = 1000 }; @@ -122,6 +99,10 @@ struct Configuration { static const ticks_per_second_t phase_lock_resolution = high_phase_lock_resolution ? milli_seconds : centi_seconds; + enum quality_factor_sync_threshold_t : uint8_t { aggressive = 1, standard = 2, conservative = 3 }; + static const uint8_t quality_factor_sync_threshold = aggressive; + + // Set to true if the library is deployed in a device runnning at room temperature. // Set to false if the library is deployed in a device operating outdoors. // The implications are as follows: @@ -138,10 +119,57 @@ struct Configuration { // The price to pay is that during DCF77 outage beyond several hours resync will take // longer. It will also imply that the crystal will never be tuned better than 1 ppm as // this is completely pointless in the presence of huge changes in ambient temperature. - static const boolean has_stable_ambient_temperature = true; // indoor deployment - // static const boolean has_stable_ambient_temperature = false; // outdoor deployment + static const bool has_stable_ambient_temperature = true; // indoor deployment + // static const bool has_stable_ambient_temperature = false; // outdoor deployment }; +// https://gcc.gnu.org/onlinedocs/cpp/Stringification.html +#define EXPAND_THEN_STRINGIFY(s) STRINGIFY(s) +#define STRINGIFY(s) #s +#define DCF77_VERSION_STRING (EXPAND_THEN_STRINGIFY(DCF77_MAJOR_VERSION) "." \ + EXPAND_THEN_STRINGIFY(DCF77_MINOR_VERSION) "." \ + EXPAND_THEN_STRINGIFY(DCF77_PATCH_VERSION)) + + +#define GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) + +#if defined(__arm__) + #define GCC_ARCHITECTURE "ARM" +#elif defined(__AVR__) + #define GCC_ARCHITECTURE "AVR" +#elif defined(__unix__) + #define GCC_ARCHITECTURE "UNIX" +#else + #define GCC_ARCHITECTURE "unknown" +#endif + + + +#define ERROR_MESSAGE(major, minor, patchlevel) compiler_version__GCC_ ## major ## _ ## minor ## _ ## patchlevel ## __ ; +#define OUTDATED_COMPILER_ERROR(major, minor, patchlevel) ERROR_MESSAGE(major, minor, patchlevel) + +#if GCC_VERSION < 40503 + // Arduino 1.0.0 - 1.0.6 come with an outdated version of avr-gcc. + // Arduino 1.5.8 comes with a ***much*** better avr-gcc. The library + // will compile but fail to execute properly if compiled with an + // outdated avr-gcc. So here we stop here if the compiler is outdated. + // + // You may find out your compiler version by executing 'avr-gcc --version' + + // Visit the compatibility section here: + // http://blog.blinkenlight.net/experiments/dcf77/dcf77-library/ + // for more details. + #error Outdated compiler version < 4.5.3 + #error Absolute minimum recommended version is avr-gcc 4.5.3. + #error Use 'avr-gcc --version' from the command line to verify your compiler version. + #error Arduino 1.0.0 - 1.0.6 ship with outdated compilers. + #error Arduino 1.5.8 (avr-gcc 4.8.1) and above are recommended. + + OUTDATED_COMPILER_ERROR(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) +#endif + namespace BCD { typedef union { @@ -506,7 +534,7 @@ namespace Internal { // --> http://www.nongnu.org/avr-libc/user-manual/atomic_8h_source.html #define CRITICAL_SECTION for (int primask_save __attribute__((__cleanup__(__int_restore_irq))) = __int_disable_irq(), __n = 1; __n; __n = 0) - #elif defined(__linux__) && defined(__unit_test__) + #elif defined(__unix__) && defined(__unit_test__) #warning Compiling for Linux target only supported for unit test purposes. Only fake support for atomic sections. Please take care. #define CRITICAL_SECTION for (int __n = 1; __n; __n = 0) @@ -1301,7 +1329,7 @@ namespace Internal { void process_1_Hz_tick(const DCF77_Encoder &decoded_time) { uint8_t quality_factor = Clock_Controller::get_overall_quality_factor(); - if (quality_factor > 1) { + if (quality_factor > Clock_Controller::Configuration::quality_factor_sync_threshold) { if (clock_state != Clock::synced) { Clock_Controller::sync_achieved_event_handler(); clock_state = Clock::synced; @@ -1519,7 +1547,7 @@ namespace Internal { #if defined(_AVR_EEPROM_H_) // indicator if data may be persisted to EEPROM - static volatile boolean data_pending; + static volatile bool data_pending; #endif // 2*tau_max = 32 004 000 ticks = 5333 minutes or 533 minutes depending on the resolution diff --git a/examples/Swiss_Army_Debug_Helper/Swiss_Army_Debug_Helper.ino b/examples/Swiss_Army_Debug_Helper/Swiss_Army_Debug_Helper.ino index fb43d62..47031b5 100644 --- a/examples/Swiss_Army_Debug_Helper/Swiss_Army_Debug_Helper.ino +++ b/examples/Swiss_Army_Debug_Helper/Swiss_Army_Debug_Helper.ino @@ -663,12 +663,32 @@ void setup() { DCF77_Clock::set_output_handler(output_handler); Serial.println(); - Serial.println(F("DCF77 Clock V3.1.1")); - Serial.println(F("(c) Udo Klein 2016")); + Serial.print(F("DCF77 Clock V")); + Serial.println(F(DCF77_VERSION_STRING)); + Serial.println(F("(c) Udo Klein 2017")); Serial.println(F("www.blinkenlight.net")); + Serial.println(); + Serial.println(F("Documentation: https://blog.blinkenlight.net/experiments/dcf77/")); + Serial.println(F("Git Repository: https://github.com/udoklein/dcf77/releases/")); + + Serial.println(); + Serial.println(F(__FILE__)); + Serial.print(F("Compiled: ")); + Serial.println(F(__TIMESTAMP__)); + Serial.print(F("Architecture: ")); + Serial.println(F(GCC_ARCHITECTURE)); + Serial.print(F("Compiler Version: ")); + Serial.println(F(__VERSION__)); + Serial.print(F("DCF77 Library Version: ")); + Serial.println(F(DCF77_VERSION_STRING)); + Serial.print(F("CPU Frequency: ")); + Serial.println(F_CPU); + Serial.println(); Serial.print(F("Phase_lock_resolution [ticks per second]: ")); Serial.println(Configuration::phase_lock_resolution); + Serial.print(F("Quality Factor Sync Threshold: ")); + Serial.println((int)Configuration::quality_factor_sync_threshold); Serial.print(F("Has stable ambient temperature: ")); Serial.println(Configuration::has_stable_ambient_temperature); diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..16de331 --- /dev/null +++ b/library.properties @@ -0,0 +1,9 @@ +name=dcf77_xtal +version=3.1.4 +author=Udo Klein dcf77@blinkenlight.net +maintainer=Udo Klein dcf77@blinkenlight.net +sentence=DCF77 decoder with excellent noise tolerance. +paragraph=Attention: this library requires a crystal based Arduino. Read the Hardware Incompatibilities Section of the documentation for more details. +category=Timing +url=https://github.com/udoklein/dcf77 +architectures=avr,arm