Revert "DCF77 + IF482 code sanitizations"

This reverts commit 160b282c3a.
This commit is contained in:
Klaus K Wilting 2019-02-08 21:48:56 +01:00
parent 160b282c3a
commit 5fcfdd91e5
5 changed files with 45 additions and 48 deletions

View File

@ -22,6 +22,7 @@ time_t get_rtctime(void);
float get_rtctemp(void); float get_rtctemp(void);
void IRAM_ATTR CLOCKIRQ(); void IRAM_ATTR CLOCKIRQ();
int pps_init(uint32_t pps_freq); int pps_init(uint32_t pps_freq);
int pps_init();
void pps_start(); void pps_start();
uint8_t sync_clock(time_t t); uint8_t sync_clock(time_t t);

View File

@ -6,11 +6,7 @@ https://www-user.tu-chemnitz.de/~heha/viewzip.cgi/hs/Funkuhr.zip/
// //
*/ */
#ifdef HAS_DCF77 #if defined HAS_DCF77
#ifdef IF_482
#error "You must define at most one of IF482 or DCF_77"
#endif
#include "dcf77.h" #include "dcf77.h"
@ -19,11 +15,6 @@ static const char TAG[] = "main";
#define DCF77_FRAME_SIZE (60) #define DCF77_FRAME_SIZE (60)
#define DCF77_PULSE_DURATION (100) #define DCF77_PULSE_DURATION (100)
#ifdef RTC_CLK
#define PPS (RTC_CLK / DCF77_PULSE_DURATION)
#else
#define PPS DCF77_PULSE_DURATION
#endif
// array of dcf pulses for three minutes // array of dcf pulses for three minutes
uint8_t DCFtimeframe[DCF77_FRAME_SIZE]; uint8_t DCFtimeframe[DCF77_FRAME_SIZE];
@ -46,7 +37,12 @@ int dcf77_init(void) {
assert(ClockTask); // has clock task started? assert(ClockTask); // has clock task started?
pps_init(PPS); // setup pulse #if defined RTC_INT && (RTC_CLK == DCF77_PULSE_DURATION)
pps_init(); // use pps clock
#else
pps_init(DCF77_PULSE_DURATION); // use esp32 clock
#endif
DCF_Out(sync_clock(now())); // sync DCF time on next second DCF_Out(sync_clock(now())); // sync DCF time on next second
pps_start(); // start pulse pps_start(); // start pulse
@ -122,10 +118,10 @@ void dcf77_loop(void *pvParameters) {
&wakeTime, // receives moment of call from isr &wakeTime, // receives moment of call from isr
portMAX_DELAY); // wait forever (missing error handling here...) portMAX_DELAY); // wait forever (missing error handling here...)
#if (PPS == DCF77_PULSE_DURATION) // we don't need clock rescaling #if !defined RTC_CLK || (RTC_CLK == DCF77_PULSE_DURATION) // we don't need clock rescaling
DCF_Out(0); DCF_Out(0);
#else // we need clock rescaling by software timer #else // we need clock rescaling by software timer
for (uint8_t i = 1; i <= PPS; i++) { for (uint8_t i = 1; i <= RTC_CLK / DCF77_PULSE_DURATION; i++) {
DCF_Out(0); DCF_Out(0);
vTaskDelayUntil(&wakeTime, pdMS_TO_TICKS(DCF77_PULSE_DURATION)); vTaskDelayUntil(&wakeTime, pdMS_TO_TICKS(DCF77_PULSE_DURATION));
} }

View File

@ -1,3 +1,5 @@
#if defined HAS_IF482
/* NOTE: /* NOTE:
The IF482 Generator needs an high precise 1 Hz clock signal which cannot be The IF482 Generator needs an high precise 1 Hz clock signal which cannot be
acquired in suitable precision on the ESP32 SoC itself. Additional clocking acquired in suitable precision on the ESP32 SoC itself. Additional clocking
@ -77,12 +79,6 @@ not evaluated by model BU-190
*/ */
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#ifdef HAS_IF482
#ifdef HAS_DCF77
#error "You must define at most one of IF482 or DCF_77"
#endif
#include "if482.h" #include "if482.h"
// Local logging tag // Local logging tag
@ -90,11 +86,6 @@ static const char TAG[] = "main";
#define IF482_FRAME_SIZE (17) #define IF482_FRAME_SIZE (17)
#define IF482_PULSE_DURATION (1000) #define IF482_PULSE_DURATION (1000)
#ifdef RTC_CLK
#define PPS (RTC_CLK / IF482_PULSE_DURATION)
#else
#define PPS IF482_PULSE_DURATION
#endif
HardwareSerial IF482(2); // use UART #2 (note: #1 may be in use for serial GPS) HardwareSerial IF482(2); // use UART #2 (note: #1 may be in use for serial GPS)
@ -115,7 +106,12 @@ int if482_init(void) {
assert(ClockTask); // has clock task started? assert(ClockTask); // has clock task started?
pps_init(PPS); // setup pulse #if defined RTC_INT && (RTC_CLK == IF482_PULSE_DURATION)
pps_init(); // use pps clock
#else
pps_init(IF482_PULSE_DURATION); // use esp32 clock
#endif
pps_start(); // start pulse pps_start(); // start pulse
return 1; // success return 1; // success
@ -174,10 +170,11 @@ void if482_loop(void *pvParameters) {
&wakeTime, // receives moment of call from isr &wakeTime, // receives moment of call from isr
portMAX_DELAY); // wait forever (missing error handling here...) portMAX_DELAY); // wait forever (missing error handling here...)
#if (PPS == DCF77_PULSE_DURATION) // we don't need clock rescaling #if !defined RTC_CLK || (RTC_CLK == IF482_PULSE_DURATION) // we don't need clock rescaling
// wait until it's time to start transmit telegram for next second // wait until it's time to start transmit telegram for next second
vTaskDelayUntil(&wakeTime, shotTime); // sets waketime to moment of shot vTaskDelayUntil(&wakeTime, shotTime); // sets waketime to moment of shot
IF482.print(IF482_Out(now() + 1)); IF482.print(IF482_Out(now() + 1));
#else // we need clock rescaling by software timer #else // we need clock rescaling by software timer
/* /*
not yet implemented for IF482 not yet implemented for IF482

View File

@ -416,7 +416,9 @@ void setup() {
setSyncInterval(TIME_SYNC_INTERVAL_GPS * 60); setSyncInterval(TIME_SYNC_INTERVAL_GPS * 60);
#endif #endif
#ifdef HAS_IF482 #if (defined HAS_IF482) && (defined DCF_77)
#error "You may define at most one of HAS_IF482 or DCF_77"
#elif defined HAS_IF482
ESP_LOGI(TAG, "Starting IF482 Generator..."); ESP_LOGI(TAG, "Starting IF482 Generator...");
assert(if482_init()); assert(if482_init());
#elif defined HAS_DCF77 #elif defined HAS_DCF77

View File

@ -1,15 +1,15 @@
#ifdef HAS_RTC
#include "rtctime.h" #include "rtctime.h"
// Local logging tag // Local logging tag
static const char TAG[] = "main"; static const char TAG[] = "main";
RtcDS3231<TwoWire> Rtc(Wire); // RTC hardware i2c interface
TaskHandle_t ClockTask; TaskHandle_t ClockTask;
hw_timer_t *clockCycle = NULL; hw_timer_t *clockCycle = NULL;
#ifdef HAS_RTC // we have hardware RTC
RtcDS3231<TwoWire> Rtc(Wire); // RTC hardware i2c interface
// initialize RTC // initialize RTC
int rtc_init(void) { int rtc_init(void) {
@ -100,11 +100,9 @@ float get_rtctemp(void) {
return 0; return 0;
} // get_rtctemp() } // get_rtctemp()
#endif // HAS_RTC int pps_init() {
// we have hardware pps signal as time base
int pps_init(uint32_t clk_freq_Hz) { #if defined RTC_INT && defined RTC_CLK
// use fixed pulse clock as time base
#if defined RTC_INT && (RTC_CLK == clk_freq_Hz)
// setup external interupt for active low RTC INT pin // setup external interupt for active low RTC INT pin
pinMode(RTC_INT, INPUT_PULLUP); pinMode(RTC_INT, INPUT_PULLUP);
@ -120,20 +118,21 @@ int pps_init(uint32_t clk_freq_Hz) {
return 0; // failure return 0; // failure
} }
return 1; // success return 1; // success
#endif
}
#else int pps_init(uint32_t pps_freq) {
// use clock with adjustable frequency // if we don't have hardware pps we use ESP32 hardware timer
if (clk_freq_Hz) { if (pps_freq) {
ESP_LOGI(TAG, "Time base ESP32 clock"); ESP_LOGI(TAG, "Time base ESP32 clock");
clockCycle = timerBegin(1, 8000, true); // set 80 MHz prescaler clockCycle = timerBegin(1, 8000, true); // set 80 MHz prescaler
timerAttachInterrupt(clockCycle, &CLOCKIRQ, true); timerAttachInterrupt(clockCycle, &CLOCKIRQ, true);
timerAlarmWrite(clockCycle, 100 * clk_freq_Hz, true); timerAlarmWrite(clockCycle, 10 * pps_freq, true);
} else { } else {
ESP_LOGE(TAG, "Invalid pulse clock frequency"); ESP_LOGE(TAG, "Invalid pps clock frequency");
return 0; // failure return 0; // failure
} }
return 1; // success return 1; // success
#endif
} }
void pps_start() { void pps_start() {
@ -161,3 +160,5 @@ void IRAM_ATTR CLOCKIRQ() {
xTaskNotifyFromISR(ClockTask, xTaskGetTickCountFromISR(), eSetBits, NULL); xTaskNotifyFromISR(ClockTask, xTaskGetTickCountFromISR(), eSetBits, NULL);
portYIELD_FROM_ISR(); portYIELD_FROM_ISR();
} }
#endif // HAS_RTC