DCF77 + IF482 code sanitizations
This commit is contained in:
parent
f319d669ec
commit
160b282c3a
@ -22,7 +22,6 @@ 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);
|
||||||
|
|
||||||
|
@ -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"
|
#include "dcf77.h"
|
||||||
|
|
||||||
@ -15,6 +19,11 @@ 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];
|
||||||
@ -37,12 +46,7 @@ int dcf77_init(void) {
|
|||||||
|
|
||||||
assert(ClockTask); // has clock task started?
|
assert(ClockTask); // has clock task started?
|
||||||
|
|
||||||
#if defined RTC_INT && (RTC_CLK == DCF77_PULSE_DURATION)
|
pps_init(PPS); // setup pulse
|
||||||
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
|
||||||
|
|
||||||
@ -118,10 +122,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 !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);
|
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 <= RTC_CLK / DCF77_PULSE_DURATION; i++) {
|
for (uint8_t i = 1; i <= PPS; i++) {
|
||||||
DCF_Out(0);
|
DCF_Out(0);
|
||||||
vTaskDelayUntil(&wakeTime, pdMS_TO_TICKS(DCF77_PULSE_DURATION));
|
vTaskDelayUntil(&wakeTime, pdMS_TO_TICKS(DCF77_PULSE_DURATION));
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#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
|
||||||
@ -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"
|
#include "if482.h"
|
||||||
|
|
||||||
// Local logging tag
|
// Local logging tag
|
||||||
@ -86,6 +90,11 @@ 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)
|
||||||
|
|
||||||
@ -106,13 +115,8 @@ int if482_init(void) {
|
|||||||
|
|
||||||
assert(ClockTask); // has clock task started?
|
assert(ClockTask); // has clock task started?
|
||||||
|
|
||||||
#if defined RTC_INT && (RTC_CLK == IF482_PULSE_DURATION)
|
pps_init(PPS); // setup pulse
|
||||||
pps_init(); // use pps clock
|
pps_start(); // start pulse
|
||||||
#else
|
|
||||||
pps_init(IF482_PULSE_DURATION); // use esp32 clock
|
|
||||||
#endif
|
|
||||||
|
|
||||||
pps_start(); // start pulse
|
|
||||||
|
|
||||||
return 1; // success
|
return 1; // success
|
||||||
} // if482_init
|
} // if482_init
|
||||||
@ -170,15 +174,14 @@ 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 !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
|
// 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
|
||||||
*/
|
*/
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
} // if482_loop()
|
} // if482_loop()
|
||||||
|
@ -65,7 +65,7 @@ char display_line6[16], display_line7[16]; // display buffers
|
|||||||
uint8_t volatile channel = 0; // channel rotation counter
|
uint8_t volatile channel = 0; // channel rotation counter
|
||||||
uint16_t volatile macs_total = 0, macs_wifi = 0, macs_ble = 0,
|
uint16_t volatile macs_total = 0, macs_wifi = 0, macs_ble = 0,
|
||||||
batt_voltage = 0; // globals for display
|
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;
|
hw_timer_t *sendCycle = NULL, *homeCycle = NULL;
|
||||||
#ifdef HAS_DISPLAY
|
#ifdef HAS_DISPLAY
|
||||||
@ -416,9 +416,7 @@ void setup() {
|
|||||||
setSyncInterval(TIME_SYNC_INTERVAL_GPS * 60);
|
setSyncInterval(TIME_SYNC_INTERVAL_GPS * 60);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (defined HAS_IF482) && (defined DCF_77)
|
#ifdef HAS_IF482
|
||||||
#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
|
||||||
|
@ -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,9 +100,11 @@ float get_rtctemp(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
} // get_rtctemp()
|
} // get_rtctemp()
|
||||||
|
|
||||||
int pps_init() {
|
#endif // HAS_RTC
|
||||||
// we have hardware pps signal as time base
|
|
||||||
#if defined RTC_INT && defined RTC_CLK
|
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
|
// setup external interupt for active low RTC INT pin
|
||||||
pinMode(RTC_INT, INPUT_PULLUP);
|
pinMode(RTC_INT, INPUT_PULLUP);
|
||||||
@ -118,21 +120,20 @@ int pps_init() {
|
|||||||
return 0; // failure
|
return 0; // failure
|
||||||
}
|
}
|
||||||
return 1; // success
|
return 1; // success
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
int pps_init(uint32_t pps_freq) {
|
#else
|
||||||
// if we don't have hardware pps we use ESP32 hardware timer
|
// use clock with adjustable frequency
|
||||||
if (pps_freq) {
|
if (clk_freq_Hz) {
|
||||||
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, 10 * pps_freq, true);
|
timerAlarmWrite(clockCycle, 100 * clk_freq_Hz, true);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(TAG, "Invalid pps clock frequency");
|
ESP_LOGE(TAG, "Invalid pulse clock frequency");
|
||||||
return 0; // failure
|
return 0; // failure
|
||||||
}
|
}
|
||||||
return 1; // success
|
return 1; // success
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void pps_start() {
|
void pps_start() {
|
||||||
@ -159,6 +160,4 @@ uint8_t sync_clock(time_t t) {
|
|||||||
void IRAM_ATTR CLOCKIRQ() {
|
void IRAM_ATTR CLOCKIRQ() {
|
||||||
xTaskNotifyFromISR(ClockTask, xTaskGetTickCountFromISR(), eSetBits, NULL);
|
xTaskNotifyFromISR(ClockTask, xTaskGetTickCountFromISR(), eSetBits, NULL);
|
||||||
portYIELD_FROM_ISR();
|
portYIELD_FROM_ISR();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // HAS_RTC
|
|
Loading…
Reference in New Issue
Block a user