Revert "Revert "DCF77 + IF482 code sanitizations""
This reverts commit 5fcfdd91e5
.
This commit is contained in:
parent
5fcfdd91e5
commit
bfc8f13cc7
@ -22,7 +22,6 @@ time_t get_rtctime(void);
|
||||
float get_rtctemp(void);
|
||||
void IRAM_ATTR CLOCKIRQ();
|
||||
int pps_init(uint32_t pps_freq);
|
||||
int pps_init();
|
||||
void pps_start();
|
||||
uint8_t sync_clock(time_t t);
|
||||
|
||||
|
@ -6,7 +6,11 @@ https://www-user.tu-chemnitz.de/~heha/viewzip.cgi/hs/Funkuhr.zip/
|
||||
//
|
||||
*/
|
||||
|
||||
#if defined HAS_DCF77
|
||||
#ifdef HAS_DCF77
|
||||
|
||||
#ifdef IF_482
|
||||
#error "You must define at most one of IF482 or DCF_77"
|
||||
#endif
|
||||
|
||||
#include "dcf77.h"
|
||||
|
||||
@ -15,6 +19,11 @@ static const char TAG[] = "main";
|
||||
|
||||
#define DCF77_FRAME_SIZE (60)
|
||||
#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
|
||||
uint8_t DCFtimeframe[DCF77_FRAME_SIZE];
|
||||
@ -37,12 +46,7 @@ int dcf77_init(void) {
|
||||
|
||||
assert(ClockTask); // has clock task started?
|
||||
|
||||
#if defined RTC_INT && (RTC_CLK == DCF77_PULSE_DURATION)
|
||||
pps_init(); // use pps clock
|
||||
#else
|
||||
pps_init(DCF77_PULSE_DURATION); // use esp32 clock
|
||||
#endif
|
||||
|
||||
pps_init(PPS); // setup pulse
|
||||
DCF_Out(sync_clock(now())); // sync DCF time on next second
|
||||
pps_start(); // start pulse
|
||||
|
||||
@ -118,10 +122,10 @@ void dcf77_loop(void *pvParameters) {
|
||||
&wakeTime, // receives moment of call from isr
|
||||
portMAX_DELAY); // wait forever (missing error handling here...)
|
||||
|
||||
#if !defined RTC_CLK || (RTC_CLK == DCF77_PULSE_DURATION) // we don't need clock rescaling
|
||||
#if (PPS == DCF77_PULSE_DURATION) // we don't need clock rescaling
|
||||
DCF_Out(0);
|
||||
#else // we need clock rescaling by software timer
|
||||
for (uint8_t i = 1; i <= RTC_CLK / DCF77_PULSE_DURATION; i++) {
|
||||
for (uint8_t i = 1; i <= PPS; i++) {
|
||||
DCF_Out(0);
|
||||
vTaskDelayUntil(&wakeTime, pdMS_TO_TICKS(DCF77_PULSE_DURATION));
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
#if defined HAS_IF482
|
||||
|
||||
/* NOTE:
|
||||
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
|
||||
@ -79,6 +77,12 @@ 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"
|
||||
|
||||
// Local logging tag
|
||||
@ -86,6 +90,11 @@ static const char TAG[] = "main";
|
||||
|
||||
#define IF482_FRAME_SIZE (17)
|
||||
#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)
|
||||
|
||||
@ -106,13 +115,8 @@ int if482_init(void) {
|
||||
|
||||
assert(ClockTask); // has clock task started?
|
||||
|
||||
#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_init(PPS); // setup pulse
|
||||
pps_start(); // start pulse
|
||||
|
||||
return 1; // success
|
||||
} // if482_init
|
||||
@ -170,15 +174,14 @@ void if482_loop(void *pvParameters) {
|
||||
&wakeTime, // receives moment of call from isr
|
||||
portMAX_DELAY); // wait forever (missing error handling here...)
|
||||
|
||||
#if !defined RTC_CLK || (RTC_CLK == IF482_PULSE_DURATION) // we don't need clock rescaling
|
||||
#if (PPS == DCF77_PULSE_DURATION) // we don't need clock rescaling
|
||||
// wait until it's time to start transmit telegram for next second
|
||||
vTaskDelayUntil(&wakeTime, shotTime); // sets waketime to moment of shot
|
||||
IF482.print(IF482_Out(now() + 1));
|
||||
|
||||
#else // we need clock rescaling by software timer
|
||||
/*
|
||||
not yet implemented for IF482
|
||||
*/
|
||||
/*
|
||||
not yet implemented for IF482
|
||||
*/
|
||||
#endif
|
||||
}
|
||||
} // if482_loop()
|
||||
|
@ -65,7 +65,7 @@ char display_line6[16], display_line7[16]; // display buffers
|
||||
uint8_t volatile channel = 0; // channel rotation counter
|
||||
uint16_t volatile macs_total = 0, macs_wifi = 0, macs_ble = 0,
|
||||
batt_voltage = 0; // globals for display
|
||||
bool volatile BitsPending = false; // DCF77 or IF482 ticker indicator
|
||||
bool volatile BitsPending = false; // DCF77 or IF482 ticker indicator
|
||||
|
||||
hw_timer_t *sendCycle = NULL, *homeCycle = NULL;
|
||||
#ifdef HAS_DISPLAY
|
||||
@ -416,9 +416,7 @@ void setup() {
|
||||
setSyncInterval(TIME_SYNC_INTERVAL_GPS * 60);
|
||||
#endif
|
||||
|
||||
#if (defined HAS_IF482) && (defined DCF_77)
|
||||
#error "You may define at most one of HAS_IF482 or DCF_77"
|
||||
#elif defined HAS_IF482
|
||||
#ifdef HAS_IF482
|
||||
ESP_LOGI(TAG, "Starting IF482 Generator...");
|
||||
assert(if482_init());
|
||||
#elif defined HAS_DCF77
|
||||
|
@ -1,15 +1,15 @@
|
||||
#ifdef HAS_RTC
|
||||
|
||||
#include "rtctime.h"
|
||||
|
||||
// Local logging tag
|
||||
static const char TAG[] = "main";
|
||||
|
||||
RtcDS3231<TwoWire> Rtc(Wire); // RTC hardware i2c interface
|
||||
|
||||
TaskHandle_t ClockTask;
|
||||
hw_timer_t *clockCycle = NULL;
|
||||
|
||||
#ifdef HAS_RTC // we have hardware RTC
|
||||
|
||||
RtcDS3231<TwoWire> Rtc(Wire); // RTC hardware i2c interface
|
||||
|
||||
// initialize RTC
|
||||
int rtc_init(void) {
|
||||
|
||||
@ -100,9 +100,11 @@ float get_rtctemp(void) {
|
||||
return 0;
|
||||
} // get_rtctemp()
|
||||
|
||||
int pps_init() {
|
||||
// we have hardware pps signal as time base
|
||||
#if defined RTC_INT && defined RTC_CLK
|
||||
#endif // HAS_RTC
|
||||
|
||||
int pps_init(uint32_t clk_freq_Hz) {
|
||||
// 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
|
||||
pinMode(RTC_INT, INPUT_PULLUP);
|
||||
@ -118,21 +120,20 @@ int pps_init() {
|
||||
return 0; // failure
|
||||
}
|
||||
return 1; // success
|
||||
#endif
|
||||
}
|
||||
|
||||
int pps_init(uint32_t pps_freq) {
|
||||
// if we don't have hardware pps we use ESP32 hardware timer
|
||||
if (pps_freq) {
|
||||
#else
|
||||
// use clock with adjustable frequency
|
||||
if (clk_freq_Hz) {
|
||||
ESP_LOGI(TAG, "Time base ESP32 clock");
|
||||
clockCycle = timerBegin(1, 8000, true); // set 80 MHz prescaler
|
||||
timerAttachInterrupt(clockCycle, &CLOCKIRQ, true);
|
||||
timerAlarmWrite(clockCycle, 10 * pps_freq, true);
|
||||
timerAlarmWrite(clockCycle, 100 * clk_freq_Hz, true);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Invalid pps clock frequency");
|
||||
ESP_LOGE(TAG, "Invalid pulse clock frequency");
|
||||
return 0; // failure
|
||||
}
|
||||
return 1; // success
|
||||
#endif
|
||||
}
|
||||
|
||||
void pps_start() {
|
||||
@ -160,5 +161,3 @@ void IRAM_ATTR CLOCKIRQ() {
|
||||
xTaskNotifyFromISR(ClockTask, xTaskGetTickCountFromISR(), eSetBits, NULL);
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
|
||||
#endif // HAS_RTC
|
Loading…
Reference in New Issue
Block a user