v1.7.14 (new feature IF482 time telegram complete)

This commit is contained in:
Klaus K Wilting committed 2019-01-27 18:19:25 +01:00
1 parent f4c29f3137
commit 7c68f7632a
10 files changed
+91 -52

No files matched your search

+1 -2
View File
@@ -25,8 +25,7 @@
#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
//#define HAS_IF482 9600, SERIAL_7E1, GPIO_NUM_12, GPIO_NUM_14 // IF482 serial port parameters
// Pins for LORA chip SPI interface, reset line and interrupt lines
#define LORA_SCK (5)
+49 -12
View File
@@ -69,10 +69,12 @@ not evaluated by model BU-190
// Local logging tag
static const char TAG[] = "main";
HardwareSerial IF482(1); // use UART #1
TaskHandle_t IF482Task;
HardwareSerial IF482(2); // use UART #2 (note: #1 may be in use for serial GPS)
// initialize and configure GPS
void if482_init(void) {
int if482_init(void) {
// open serial interface
IF482.begin(HAS_IF482);
@@ -84,6 +86,8 @@ void if482_init(void) {
ESP_LOGI(TAG, "IF482 generator initialized");
return 1;
} // if482_init
String if482Telegram(time_t t) {
@@ -93,31 +97,64 @@ String if482Telegram(time_t t) {
char out[17];
switch (timeStatus()) { // indicates if time has been set and recently synced
case timeSet: // time is set and is synced
case timeSet: // time is set and is synced
mon = 'A';
break;
case timeNeedsSync: // time had been set but sync attempt did not succeed
mon = 'M';
break;
default: // time not set, no valid time
mon = '?';
break;
} // switch
if (!timeNotSet) // do we have valid time?
snprintf(buf, sizeof buf, "%02u%02u%02u%1u%02u%02u%02u", year(t)-2000, month(t),
day(t), weekday(t), hour(t), minute(t), second(t));
snprintf(buf, sizeof buf, "%02u%02u%02u%1u%02u%02u%02u", year(t) - 2000,
month(t), day(t), weekday(t), hour(t), minute(t), second(t));
snprintf(out, sizeof out, "O%cL%s\r", mon, buf);
return out;
}
// interrupt triggered routine
void sendIF482(time_t t) { IF482.print(if482Telegram(t)); }
void if482_loop(void *pvParameters) {
configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
TickType_t wakeTime;
time_t t, tt;
const TickType_t shotTime = pdMS_TO_TICKS(IF482_OFFSET);
// wait until begin of a new second
t = tt = now();
do {
tt = now();
} while (t == tt);
const TickType_t startTime = xTaskGetTickCount();
// task remains in blocked state until it is notified by isr
for (;;) {
xTaskNotifyWait(
0x00, // don't clear any bits on entry
ULONG_MAX, // clear all bits on exit
&wakeTime, // receives moment of call from isr
portMAX_DELAY); // wait forever (missing error handling here...)
t = now();
wakeTime -= startTime;
// now we're synced to start of second t and wait
// until it's time to start transmit telegram for t+1
vTaskDelayUntil(&wakeTime, shotTime);
IF482.print(if482Telegram(t + 1));
}
vTaskDelete(IF482Task); // shoud never be reached
} // if482_loop()
// interrupt service routine triggered by RTC 1Hz precise clock
void IRAM_ATTR IF482IRQ() {
xTaskNotifyFromISR(IF482Task, xTaskGetTickCountFromISR(), eSetBits, NULL);
portYIELD_FROM_ISR();
}
#endif // HAS_IF482
-13
View File
@@ -18,12 +18,6 @@ void irqHandler(void *pvParameters) {
&InterruptStatus, // Receives the notification value
portMAX_DELAY); // wait forever (missing error handling here...)
// IF482 interrupt?
#ifdef HAS_IF482
if (InterruptStatus & IF482_IRQ)
sendIF482(now());
#endif
// button pressed?
#ifdef HAS_BUTTON
if (InterruptStatus & BUTTON_IRQ)
@@ -78,10 +72,3 @@ void IRAM_ATTR ButtonIRQ() {
portYIELD_FROM_ISR();
}
#endif
#ifdef HAS_IF482
void IRAM_ATTR IF482IRQ() {
xTaskNotifyFromISR(irqHandlerTask, IF482_IRQ, eSetBits, NULL);
portYIELD_FROM_ISR();
}
#endif
+22 -8
View File
@@ -29,6 +29,7 @@ Task Core Prio Purpose
====================================================================================
wifiloop 0 4 rotates wifi channels
ledloop 0 3 blinks LEDs
if482loop 1 3 serial feed of IF482 time telegrams
spiloop 0 2 reads/writes data on spi interface
IDLE 0 0 ESP32 arduino scheduler -> runs wifi sniffer
@@ -44,11 +45,15 @@ Tasks using i2c bus all must have same priority, because using mutex semaphore
(irqhandler, bmeloop)
ESP32 hardware timers
==========================
0 Trigger display refresh
1 Trigger Wifi channel switch
2 Trigger send payload cycle
3 Trigger housekeeping cycle
================================
0 triggers display refresh
1 triggers Wifi channel switch
2 triggers send payload cycle
3 triggers housekeeping cycle
RTC hardware timer (if present)
================================
triggers IF482 clock generator
*/
@@ -185,9 +190,18 @@ void setup() {
sync_rtctime();
#ifdef HAS_IF482
strcat_P(features, " IF482");
if482_init();
#endif
#endif
if (if482_init()) {
ESP_LOGI(TAG, "Starting IF482loop...");
xTaskCreatePinnedToCore(if482_loop, // task function
"if482loop", // name of task
2048, // stack size of task
(void *)1, // parameter of the task
3, // priority of the task
&IF482Task, // task handle
0); // CPU core
}
#endif // HAS_IF482
#endif // HAS_RTC
// initialize wifi antenna
#ifdef HAS_ANTENNA_SWITCH
+4 -3
View File
@@ -81,9 +81,10 @@
#define OTA_MIN_BATT 3600 // minimum battery level for OTA [millivolt]
#define RESPONSE_TIMEOUT_MS 60000 // firmware binary server connection timeout [milliseconds]
// setting for syncing time of node
#define TIME_SYNC_INTERVAL 60 // sync time each ... minutes with external source [default = 60], comment out means off
// settings for syncing time of node and external time sources
//#define TIME_SYNC_INTERVAL 60 // sync time each ... minutes with external source [default = 60], comment out means off
#define TIME_SYNC_INTERVAL_RTC 5 // sync time each ... minutes with RTC [default = 5], comment out means off
#define IF482_OFFSET 984 // 1sec minus IF482 serial transmit time [ms]: e.g. 9 bits * 17 bytes * 1/9600 bps = 16ms
// LMIC settings
// moved to src/lmic_config.h
// moved to src/lmic_config.h