added IF482 time telegram generator (experimental)
This commit is contained in:
parent
8d3d4fe812
commit
44b821f2a5
@ -2,5 +2,9 @@
|
|||||||
#define _IF482_H
|
#define _IF482_H
|
||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
#include "irqhandler.h"
|
||||||
|
|
||||||
|
void if482_init(void);
|
||||||
|
void sendIF482(time_t t);
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -5,6 +5,7 @@
|
|||||||
#define BUTTON_IRQ 0x02
|
#define BUTTON_IRQ 0x02
|
||||||
#define SENDCOUNTER_IRQ 0x04
|
#define SENDCOUNTER_IRQ 0x04
|
||||||
#define CYCLIC_IRQ 0x08
|
#define CYCLIC_IRQ 0x08
|
||||||
|
#define IF482_IRQ 0x10
|
||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "cyclic.h"
|
#include "cyclic.h"
|
||||||
@ -25,4 +26,10 @@ void IRAM_ATTR DisplayIRQ();
|
|||||||
void IRAM_ATTR ButtonIRQ();
|
void IRAM_ATTR ButtonIRQ();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAS_IF482
|
||||||
|
#include "if482.h"
|
||||||
|
void IRAM_ATTR IF482IRQ();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -18,6 +18,8 @@ typedef enum {
|
|||||||
synced_GPS = 4 // best possible quality, clock is driven by GPS
|
synced_GPS = 4 // best possible quality, clock is driven by GPS
|
||||||
} clock_state_t;
|
} clock_state_t;
|
||||||
|
|
||||||
|
extern RtcDS3231<TwoWire> Rtc; // make RTC instance globally available
|
||||||
|
|
||||||
int rtc_init(void);
|
int rtc_init(void);
|
||||||
void sync_rtctime(void);
|
void sync_rtctime(void);
|
||||||
int set_rtctime(uint32_t UTCTime);
|
int set_rtctime(uint32_t UTCTime);
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C
|
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C
|
||||||
#define HAS_LED NOT_A_PIN // green on board LED is useless, is GPIO25, which switches power for Lora+Display
|
#define HAS_LED NOT_A_PIN // green on board LED is useless, is GPIO25, which switches power for Lora+Display
|
||||||
//#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
|
|
||||||
#define HAS_LOWPOWER_SWITCH GPIO_NUM_25 // switches power for LoRa chip + display (0 = off / 1 = on)
|
#define HAS_LOWPOWER_SWITCH GPIO_NUM_25 // switches power for LoRa chip + display (0 = off / 1 = on)
|
||||||
#define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL
|
#define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL
|
||||||
#define BATT_FACTOR 2 // voltage divider 100k/100k on board
|
#define BATT_FACTOR 2 // voltage divider 100k/100k on board
|
||||||
@ -23,6 +22,11 @@
|
|||||||
|
|
||||||
// Pins for on board DS3231 RTC chip
|
// Pins for on board DS3231 RTC chip
|
||||||
#define HAS_RTC MY_OLED_SDA, MY_OLED_SCL // SDA, SCL
|
#define HAS_RTC MY_OLED_SDA, MY_OLED_SCL // SDA, SCL
|
||||||
|
#define RTC_INT GPIO_NUM_34 // interrupt input from rtc
|
||||||
|
|
||||||
|
// Settings for IF482 interface
|
||||||
|
#define HAS_IF482 9600, SERIAL_7E1, GPIO_NUM_12, GPIO_NUM_15 // IF482 serial port parameters
|
||||||
|
#define IF482_PORT 1 // serial port 1
|
||||||
|
|
||||||
// Pins for LORA chip SPI interface, reset line and interrupt lines
|
// Pins for LORA chip SPI interface, reset line and interrupt lines
|
||||||
#define LORA_SCK (5)
|
#define LORA_SCK (5)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifdef HAS_IF482
|
#if defined HAS_IF482 && defined HAS_RTC
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
IF482 Generator to control clocks with IF482 timeframe input (e.g. BÜRK BU190)
|
IF482 Generator to control clocks with IF482 timeframe input (e.g. BÜRK BU190)
|
||||||
|
|
||||||
Example IF482 timeframe: "OAL160806F170400"
|
Example IF482 timeframe: "OAL160806F170400"
|
||||||
@ -51,5 +52,64 @@ Wird überprüft, jedoch nicht vom Uhrwerk ausgewertet.
|
|||||||
// Local logging tag
|
// Local logging tag
|
||||||
static const char TAG[] = "main";
|
static const char TAG[] = "main";
|
||||||
|
|
||||||
|
HardwareSerial IF482(IF482_PORT); // serial port 1
|
||||||
|
|
||||||
|
// initialize and configure GPS
|
||||||
|
void if482_init(void) {
|
||||||
|
|
||||||
|
IF482.begin(HAS_IF482);
|
||||||
|
ESP_LOGI(TAG, "IF482 serial port opened");
|
||||||
|
|
||||||
|
// use rtc 1Hz clock for triggering IF482 telegram send
|
||||||
|
Rtc.SetSquareWavePinClockFrequency(DS3231SquareWaveClock_1Hz);
|
||||||
|
Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeClock);
|
||||||
|
|
||||||
|
// setup external interupt for active low RTC INT pin
|
||||||
|
attachInterrupt(RTC_INT, IF482IRQ, FALLING);
|
||||||
|
|
||||||
|
} // if482_init
|
||||||
|
|
||||||
|
char * if482Telegram(time_t t) {
|
||||||
|
|
||||||
|
static char out[17] = {0}; // 16 bytes IF482 telegram plus null termination char
|
||||||
|
char buf[14] = {0};
|
||||||
|
|
||||||
|
strcat_P(out, "O"); // <STX>
|
||||||
|
|
||||||
|
switch (timeStatus()) { // indicates if time has been set and recently synced
|
||||||
|
|
||||||
|
case timeSet: // time is set and is synced
|
||||||
|
strcat_P(out, "A");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case timeNeedsSync: // time had been set but sync attempt did not succeed
|
||||||
|
strcat_P(out, "M");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: // time not set, no valid time
|
||||||
|
strcat_P(out, "?");
|
||||||
|
break;
|
||||||
|
|
||||||
|
} // switch
|
||||||
|
|
||||||
|
strcat_P(out, "L"); // local time
|
||||||
|
|
||||||
|
if (!timeNotSet) { // do we have valid time?
|
||||||
|
sprintf(buf, "%02u%02u%02uF%02u%02u%02u", year(t), month(t), day(t), hour(t),
|
||||||
|
minute(t), second(t));
|
||||||
|
strcat(out, buf);
|
||||||
|
} else {
|
||||||
|
strcat_P(out, "000000F000000");
|
||||||
|
}
|
||||||
|
|
||||||
|
strcat_P(out, "\r"); // <ETX>
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// interrupt triggered routine
|
||||||
|
void sendIF482(time_t t) {
|
||||||
|
IF482.write(if482Telegram(t));
|
||||||
|
}
|
||||||
|
|
||||||
#endif // HAS_IF482
|
#endif // HAS_IF482
|
@ -18,6 +18,12 @@ void irqHandler(void *pvParameters) {
|
|||||||
&InterruptStatus, // Receives the notification value
|
&InterruptStatus, // Receives the notification value
|
||||||
portMAX_DELAY); // wait forever (missing error handling here...)
|
portMAX_DELAY); // wait forever (missing error handling here...)
|
||||||
|
|
||||||
|
// IF482 interrupt?
|
||||||
|
#ifdef HAS_IF482
|
||||||
|
if (InterruptStatus & IF482_IRQ)
|
||||||
|
sendIF482(now());
|
||||||
|
#endif
|
||||||
|
|
||||||
// button pressed?
|
// button pressed?
|
||||||
#ifdef HAS_BUTTON
|
#ifdef HAS_BUTTON
|
||||||
if (InterruptStatus & BUTTON_IRQ)
|
if (InterruptStatus & BUTTON_IRQ)
|
||||||
@ -61,7 +67,7 @@ void IRAM_ATTR SendCycleIRQ() {
|
|||||||
|
|
||||||
#ifdef HAS_DISPLAY
|
#ifdef HAS_DISPLAY
|
||||||
void IRAM_ATTR DisplayIRQ() {
|
void IRAM_ATTR DisplayIRQ() {
|
||||||
xTaskNotifyFromISR(irqHandlerTask, DISPLAY_IRQ, eSetBits, NULL);
|
xTaskNotifyFromISR(irqHandlerTask, DISPLAY_IRQ, eSetBits, NULL);
|
||||||
portYIELD_FROM_ISR();
|
portYIELD_FROM_ISR();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -72,3 +78,10 @@ void IRAM_ATTR ButtonIRQ() {
|
|||||||
portYIELD_FROM_ISR();
|
portYIELD_FROM_ISR();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAS_IF482
|
||||||
|
void IRAM_ATTR IF482IRQ() {
|
||||||
|
xTaskNotifyFromISR(irqHandlerTask, IF482_IRQ, eSetBits, NULL);
|
||||||
|
portYIELD_FROM_ISR();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -42,6 +42,7 @@ int rtc_init(void) {
|
|||||||
// configure RTC chip
|
// configure RTC chip
|
||||||
Rtc.Enable32kHzPin(false);
|
Rtc.Enable32kHzPin(false);
|
||||||
Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeNone);
|
Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeNone);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(TAG, "I2c bus busy - RTC initialization error");
|
ESP_LOGE(TAG, "I2c bus busy - RTC initialization error");
|
||||||
goto error;
|
goto error;
|
||||||
|
Loading…
Reference in New Issue
Block a user