diff --git a/include/if482.h b/include/if482.h index def3a2fe..b38013d8 100644 --- a/include/if482.h +++ b/include/if482.h @@ -6,5 +6,7 @@ int if482_init(void); void if482_loop(void *pvParameters); +TickType_t tx_time(unsigned long baud, uint32_t config, int8_t rxPin, + int8_t txPins); #endif \ No newline at end of file diff --git a/src/dcf77.cpp b/src/dcf77.cpp index 8be4ed61..f77486c5 100644 --- a/src/dcf77.cpp +++ b/src/dcf77.cpp @@ -39,6 +39,7 @@ int dcf77_init(void) { pinMode(HAS_DCF77, OUTPUT); set_DCF77_pin(dcf_low); + timepulse_init(PPS); // setup timepulse xTaskCreatePinnedToCore(dcf77_loop, // task function "dcf77loop", // name of task @@ -49,8 +50,6 @@ int dcf77_init(void) { 0); // CPU core assert(ClockTask); // has clock task started? - - timepulse_init(PPS); // setup pulse DCF_Out(sync_clock(now())); // sync DCF time on next second timepulse_start(); // start pulse diff --git a/src/if482.cpp b/src/if482.cpp index 97aff8c4..c08cdec3 100644 --- a/src/if482.cpp +++ b/src/if482.cpp @@ -107,6 +107,8 @@ int if482_init(void) { // open serial interface IF482.begin(HAS_IF482); + // setup timepulse + timepulse_init(PPS); // start if482 serial output feed task xTaskCreatePinnedToCore(if482_loop, // task function @@ -118,9 +120,7 @@ int if482_init(void) { 0); // CPU core assert(ClockTask); // has clock task started? - - timepulse_init(PPS); // setup pulse - timepulse_start(); // start pulse + timepulse_start(); // start pulse return 1; // success } // if482_init @@ -161,7 +161,7 @@ void if482_loop(void *pvParameters) { TickType_t wakeTime; const TickType_t timeOffset = - pdMS_TO_TICKS(IF482_OFFSET); // duration of telegram transmit + tx_time(HAS_IF482); // duration of telegram transmit const TickType_t startTime = xTaskGetTickCount(); // now sync_clock(now()); // wait until begin of a new second @@ -196,4 +196,15 @@ void if482_loop(void *pvParameters) { } } // if482_loop() +// helper function to calculate IF482 telegram serial tx time from serial +// settings +TickType_t tx_time(unsigned long baud, uint32_t config, int8_t rxPin, + int8_t txPins) { + + uint32_t datenbits = ((config & 0x0c) >> 2) + 5; + uint32_t startbits = ((config & 0x20) >> 5) + 1; + return pdMS_TO_TICKS( + round(((datenbits + startbits + 1) * IF482_FRAME_SIZE * 1000.0 / baud))); +} + #endif // HAS_IF482 \ No newline at end of file diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 1b6d6c3a..555a0491 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -82,12 +82,11 @@ #define RESPONSE_TIMEOUT_MS 60000 // firmware binary server connection timeout [milliseconds] // settings for syncing time of node and external time sources -#define TIME_SYNC_INTERVAL_GPS 60 // sync time each .. minutes from source GPS [default = 60], comment out means off +#define TIME_SYNC_INTERVAL_GPS 5 // sync time each .. minutes from source GPS [default = 5], comment out means off #define TIME_SYNC_INTERVAL_RTC 60 // sync time each .. minutes from RTC [default = 60], comment out means off #define TIME_WRITE_INTERVAL_RTC 60 // write time each .. minutes from GPS/LORA to RTC [default = 60], comment out means off //#define TIME_SYNC_INTERVAL_LORA 60 // sync time each .. minutes from LORA network [default = 60], comment out means off #define TIME_SYNC_INTERVAL_DCF 60 // sync DCF signal time each .. minutes from internal time [default = 60], comment out means off -#define IF482_OFFSET 16 // IF482 serial transmit time [ms]: e.g. 9 bits * 17 bytes * 1/9600 bps = 16ms // time zone, see https://github.com/JChristensen/Timezone/blob/master/examples/WorldClock/WorldClock.ino #define DAYLIGHT_TIME {"CEST", Last, Sun, Mar, 2, 120} // Central European Summer Time diff --git a/src/rtctime.cpp b/src/rtctime.cpp index d59f574b..7c120ac7 100644 --- a/src/rtctime.cpp +++ b/src/rtctime.cpp @@ -136,6 +136,7 @@ int timepulse_init(uint32_t pulse_period_ms) { Rtc.SetSquareWavePinClockFrequency(DS3231SquareWaveClock_1kHz); break; default: + I2C_MUTEX_UNLOCK(); goto pulse_period_error; } Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeClock);