diff --git a/include/dcf77.h b/include/dcf77.h index e8b7266f..5e48aa19 100644 --- a/include/dcf77.h +++ b/include/dcf77.h @@ -13,9 +13,10 @@ enum dcf_pinstate { dcf_low, dcf_high }; #endif enum dcf_pulses { dcf_off, dcf_zero, dcf_one }; +extern uint8_t DCFpulse[]; void DCF_Pulse(time_t t); -uint8_t IRAM_ATTR DCF77_Frame(time_t t); +void IRAM_ATTR DCF77_Frame(time_t t); uint8_t IRAM_ATTR dec2bcd(uint8_t dec, uint8_t startpos, uint8_t endpos, uint8_t pArray[]); uint8_t IRAM_ATTR setParityBit(uint8_t p); diff --git a/src/dcf77.cpp b/src/dcf77.cpp index b8ca988e..adc4ecca 100644 --- a/src/dcf77.cpp +++ b/src/dcf77.cpp @@ -18,7 +18,7 @@ static const char TAG[] = "main"; // array of dcf pulses for one minute, secs 0..16 and 20 are never touched, so // we initialize them statically to avoid dumb recalculation every minute -static uint8_t DCFpulse[DCF77_FRAME_SIZE] = { +uint8_t DCFpulse[DCF77_FRAME_SIZE + 1] = { dcf_zero, dcf_zero, dcf_zero, dcf_zero, dcf_zero, dcf_zero, dcf_zero, dcf_zero, dcf_zero, dcf_zero, dcf_zero, dcf_zero, dcf_zero, dcf_zero, dcf_zero, dcf_zero, dcf_zero, dcf_zero, dcf_zero, dcf_zero, dcf_one}; @@ -63,7 +63,7 @@ void DCF_Pulse(time_t t) { } // for } // DCF_Pulse() -uint8_t IRAM_ATTR DCF77_Frame(time_t tt) { +void IRAM_ATTR DCF77_Frame(time_t tt) { uint8_t Parity; time_t t = myTZ.toLocal(tt); // convert to local time @@ -94,8 +94,8 @@ uint8_t IRAM_ATTR DCF77_Frame(time_t tt) { // ENCODE MARK (sec 59) DCFpulse[59] = dcf_off; // !! missing code here for leap second !! - // return the minute for which this frame is generated - return minute(t); + // timestamp this frame with it's minute + DCFpulse[60] = minute(t); } // DCF77_Frame() diff --git a/src/timemanager.cpp b/src/timemanager.cpp index f78f4127..07459a00 100644 --- a/src/timemanager.cpp +++ b/src/timemanager.cpp @@ -190,14 +190,13 @@ void clock_loop(void *pvParameters) { // ClockTask TickType_t wakeTime; time_t t; - uint8_t current_frame; #define t1(t) (t + DCF77_FRAME_SIZE + 1) // future time for next DCF77 frame #define t2(t) (t + 1) // future time for sync with 1pps trigger // preload first DCF frame before start #ifdef HAS_DCF77 - current_frame = DCF77_Frame(t1(now())); + DCF77_Frame(t1(now())); #endif // output time telegram for second following sec beginning with timepulse @@ -217,9 +216,9 @@ void clock_loop(void *pvParameters) { // ClockTask #elif defined HAS_DCF77 if (second(t) == DCF77_FRAME_SIZE - 1) // is it time to load new frame? - current_frame = DCF77_Frame(t1(t)); // generate next frame + DCF77_Frame(t1(t)); // generate next frame - if (current_frame == + if (DCFpulse[DCF77_FRAME_SIZE] == minute(t1(t))) // have recent frame? (pulses could be missed!) DCF_Pulse(t2(t)); // then output next second of this frame