changed hardware timers to soft timers with task notify

This commit is contained in:
cyberman54 2019-03-03 00:30:57 +01:00
parent 1ae444b342
commit b516cbbbce
16 changed files with 51 additions and 51 deletions

View File

@ -11,6 +11,9 @@
#include "bme680mems.h" #include "bme680mems.h"
#endif #endif
extern Ticker housekeeper;
void housekeeping(void);
void doHousekeeping(void); void doHousekeeping(void);
uint64_t uptime(void); uint64_t uptime(void);
void reset_counters(void); void reset_counters(void);

View File

@ -8,6 +8,7 @@
#include <Time.h> #include <Time.h>
#include <Timezone.h> #include <Timezone.h>
#include <RtcDateTime.h> #include <RtcDateTime.h>
#include <Ticker.h>
// std::set for unified array functions // std::set for unified array functions
#include <set> #include <set>

View File

@ -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 TIMESYNC_IRQ 0x10
#include "globals.h" #include "globals.h"
#include "cyclic.h" #include "cyclic.h"
@ -12,8 +13,6 @@
#include "timekeeper.h" #include "timekeeper.h"
void irqHandler(void *pvParameters); void irqHandler(void *pvParameters);
void IRAM_ATTR homeCycleIRQ();
void IRAM_ATTR SendCycleIRQ();
#ifdef HAS_DISPLAY #ifdef HAS_DISPLAY
#include "display.h" #include "display.h"

View File

@ -5,9 +5,12 @@
#include "lorawan.h" #include "lorawan.h"
#include "cyclic.h" #include "cyclic.h"
extern Ticker sendcycler;
void SendPayload(uint8_t port, sendprio_t prio); void SendPayload(uint8_t port, sendprio_t prio);
void sendCounter(void); void sendCounter(void);
void checkSendQueues(void); void checkSendQueues(void);
void flushQueues(); void flushQueues();
void sendcycle(void);
#endif // _SENDDATA_H_ #endif // _SENDDATA_H_

View File

@ -4,6 +4,7 @@
#include "globals.h" #include "globals.h"
#include "rtctime.h" #include "rtctime.h"
#include "TimeLib.h" #include "TimeLib.h"
#include "irqhandler.h"
#ifdef HAS_GPS #ifdef HAS_GPS
#include "gpsread.h" #include "gpsread.h"
@ -15,11 +16,13 @@
#endif #endif
extern const char timeSetSymbols[]; extern const char timeSetSymbols[];
extern Ticker timesyncer;
void IRAM_ATTR CLOCKIRQ(void); void IRAM_ATTR CLOCKIRQ(void);
void clock_init(void); void clock_init(void);
void clock_loop(void *pvParameters); void clock_loop(void *pvParameters);
void timepulse_start(void); void timepulse_start(void);
void timeSync(void);
uint8_t timepulse_init(void); uint8_t timepulse_init(void);
time_t timeIsValid(time_t const t); time_t timeIsValid(time_t const t);
time_t timeProvider(void); time_t timeProvider(void);

View File

@ -260,10 +260,9 @@ time_t sysUnsyncedTime = 0; // the time sysTime unadjusted by sync
#endif #endif
#ifdef usePPS #ifdef usePPS
time_t SyncToPPS() { void SyncToPPS() {
sysTime++; sysTime++;
prevMicros = micros(); prevMicros = micros();
return sysTime;
} }
#endif #endif

View File

@ -154,7 +154,7 @@ time_t now(uint32_t &sysTimeMicros); // return the current time as seconds and
#endif #endif
#ifdef usePPS #ifdef usePPS
time_t SyncToPPS(); void SyncToPPS();
#endif #endif
void setTime(time_t t); void setTime(time_t t);
void setTime(int hr, int min, int sec, int day, int month, int yr); void setTime(int hr, int min, int sec, int day, int month, int yr);

View File

@ -19,7 +19,7 @@ void defaultConfig() {
cfg.screenon = 1; // 0=disabled, 1=enabled cfg.screenon = 1; // 0=disabled, 1=enabled
cfg.countermode = 0; // 0=cyclic, 1=cumulative, 2=cyclic confirmed cfg.countermode = 0; // 0=cyclic, 1=cumulative, 2=cyclic confirmed
cfg.rssilimit = 0; // threshold for rssilimiter, negative value! cfg.rssilimit = 0; // threshold for rssilimiter, negative value!
cfg.sendcycle = SEND_SECS; // payload send cycle [seconds/2] cfg.sendcycle = SEND_CYCLE; // payload send cycle [seconds/2]
cfg.wifichancycle = cfg.wifichancycle =
WIFI_CHANNEL_SWITCH_INTERVAL; // wifi channel switch cycle [seconds/100] WIFI_CHANNEL_SWITCH_INTERVAL; // wifi channel switch cycle [seconds/100]
cfg.blescantime = cfg.blescantime =

View File

@ -7,6 +7,10 @@
// Local logging tag // Local logging tag
static const char TAG[] = __FILE__; static const char TAG[] = __FILE__;
Ticker housekeeper;
void housekeeping() { xTaskNotify(irqHandlerTask, CYCLIC_IRQ, eSetBits); }
// do all housekeeping // do all housekeeping
void doHousekeeping() { void doHousekeeping() {

View File

@ -95,7 +95,7 @@ time_t get_gpstime(void) {
if ((gps.time.age() < gpsDelay_ms) && (gps.time.isValid()) && if ((gps.time.age() < gpsDelay_ms) && (gps.time.isValid()) &&
(gps.date.isValid())) { (gps.date.isValid())) {
ESP_LOGD(TAG, "GPS time age: %dms, is valid: %s, second: %d,", ESP_LOGD(TAG, "GPS time age: %dms, is valid: %s, second: %d",
gps.time.age(), gps.time.age(),
(gps.time.isValid() && gps.date.isValid()) ? "yes" : "no", (gps.time.isValid() && gps.date.isValid()) ? "yes" : "no",
gps.time.second()); gps.time.second());

View File

@ -34,6 +34,11 @@ void irqHandler(void *pvParameters) {
doHousekeeping(); doHousekeeping();
} }
// time to be synced?
if (InterruptStatus & TIMESYNC_IRQ) {
setTime(timeProvider());
}
// is time to send the payload? // is time to send the payload?
if (InterruptStatus & SENDCOUNTER_IRQ) if (InterruptStatus & SENDCOUNTER_IRQ)
sendCounter(); sendCounter();
@ -44,16 +49,6 @@ void irqHandler(void *pvParameters) {
// esp32 hardware timer triggered interrupt service routines // esp32 hardware timer triggered interrupt service routines
// they notify the irq handler task // they notify the irq handler task
void IRAM_ATTR homeCycleIRQ() {
xTaskNotifyFromISR(irqHandlerTask, CYCLIC_IRQ, eSetBits, NULL);
portYIELD_FROM_ISR();
}
void IRAM_ATTR SendCycleIRQ() {
xTaskNotifyFromISR(irqHandlerTask, SENDCOUNTER_IRQ, eSetBits, NULL);
portYIELD_FROM_ISR();
}
#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);

View File

@ -313,16 +313,6 @@ void setup() {
timerAlarmWrite(displaytimer, DISPLAYREFRESH_MS * 1000, true); timerAlarmWrite(displaytimer, DISPLAYREFRESH_MS * 1000, true);
#endif #endif
// setup send cycle trigger IRQ using esp32 hardware timer 2
sendCycle = timerBegin(2, 8000, true);
timerAttachInterrupt(sendCycle, &SendCycleIRQ, true);
timerAlarmWrite(sendCycle, cfg.sendcycle * 2 * 10000, true);
// setup house keeping cycle trigger IRQ using esp32 hardware timer 3
homeCycle = timerBegin(3, 8000, true);
timerAttachInterrupt(homeCycle, &homeCycleIRQ, true);
timerAlarmWrite(homeCycle, HOMECYCLE * 10000, true);
// show payload encoder // show payload encoder
#if PAYLOAD_ENCODER == 1 #if PAYLOAD_ENCODER == 1
strcat_P(features, " PLAIN"); strcat_P(features, " PLAIN");
@ -358,19 +348,6 @@ void setup() {
#endif #endif
#endif #endif
#if defined HAS_IF482 || defined HAS_DCF77
// start pps timepulse
ESP_LOGI(TAG, "Starting Timekeeper...");
assert(timepulse_init()); // setup timepulse
timepulse_start();
#endif
#ifdef TIME_SYNC_INTERVAL
// set time source and sync time
setSyncInterval(TIME_SYNC_INTERVAL * 60);
setSyncProvider(&timeProvider);
#endif
// start wifi in monitor mode and start channel rotation timer // start wifi in monitor mode and start channel rotation timer
ESP_LOGI(TAG, "Starting Wifi..."); ESP_LOGI(TAG, "Starting Wifi...");
wifi_sniffer_init(); wifi_sniffer_init();
@ -406,12 +383,12 @@ void setup() {
assert(irqHandlerTask != NULL); // has interrupt handler task started? assert(irqHandlerTask != NULL); // has interrupt handler task started?
// start timer triggered interrupts // start timer triggered interrupts
ESP_LOGI(TAG, "Starting Interrupts..."); ESP_LOGI(TAG, "Starting Timers...");
#ifdef HAS_DISPLAY #ifdef HAS_DISPLAY
timerAlarmEnable(displaytimer); timerAlarmEnable(displaytimer);
#endif #endif
timerAlarmEnable(sendCycle); sendcycler.attach(SEND_CYCLE, sendcycle);
timerAlarmEnable(homeCycle); housekeeper.attach(HOMECYCLE, housekeeping);
// start button interrupt // start button interrupt
#ifdef HAS_BUTTON #ifdef HAS_BUTTON
@ -422,7 +399,19 @@ void setup() {
#endif #endif
#endif // HAS_BUTTON #endif // HAS_BUTTON
#ifdef TIME_SYNC_INTERVAL
// start pps timepulse
ESP_LOGI(TAG, "Starting Timekeeper...");
assert(timepulse_init()); // setup timepulse
timepulse_start();
timeSync(); // init systime
timesyncer.attach(TIME_SYNC_INTERVAL * 60, timeSync);
#endif
#if defined HAS_IF482 || defined HAS_DCF77 #if defined HAS_IF482 || defined HAS_DCF77
#ifndef TIME_SYNC_INTERVAL
#error you must define TIME_SNYC_INTERVAL in paxcounter.conf
#endif
ESP_LOGI(TAG, "Starting Clock Controller..."); ESP_LOGI(TAG, "Starting Clock Controller...");
clock_init(); clock_init();
#endif #endif

View File

@ -10,7 +10,7 @@
#define VERBOSE 1 // comment out to silence the device, for mute use build option #define VERBOSE 1 // comment out to silence the device, for mute use build option
// Payload send cycle and encoding // Payload send cycle and encoding
#define SEND_SECS 30 // payload send cycle [seconds/2] -> 60 sec. #define SEND_CYCLE 30 // payload send cycle [seconds/2] -> 60 sec.
#define PAYLOAD_ENCODER 2 // payload encoder: 1=Plain, 2=Packed, 3=Cayenne LPP dynamic, 4=Cayenne LPP packed #define PAYLOAD_ENCODER 2 // payload encoder: 1=Plain, 2=Packed, 3=Cayenne LPP dynamic, 4=Cayenne LPP packed
// Set this to include BLE counting and vendor filter functions // Set this to include BLE counting and vendor filter functions

View File

@ -456,7 +456,7 @@ void PayloadConvert::addButton(uint8_t value) {
void PayloadConvert::addTime(time_t value) { void PayloadConvert::addTime(time_t value) {
#if (PAYLOAD_ENCODER == 4) #if (PAYLOAD_ENCODER == 4)
uint32_t t = (uint32_t)value; uint32_t t = (uint32_t)value;
uint32_t tx_period = (uint32_t)SEND_SECS * 2; uint32_t tx_period = (uint32_t)SEND_CYCLE * 2;
buffer[cursor++] = 0x03; // set config mask to UTCTime + TXPeriod buffer[cursor++] = 0x03; // set config mask to UTCTime + TXPeriod
// UTCTime in seconds // UTCTime in seconds
buffer[cursor++] = (byte)((t & 0xFF000000) >> 24); buffer[cursor++] = (byte)((t & 0xFF000000) >> 24);

View File

@ -1,6 +1,10 @@
// Basic Config // Basic Config
#include "senddata.h" #include "senddata.h"
Ticker sendcycler;
void sendcycle() { xTaskNotify(irqHandlerTask, SENDCOUNTER_IRQ, eSetBits); }
// put data to send in RTos Queues used for transmit over channels Lora and SPI // put data to send in RTos Queues used for transmit over channels Lora and SPI
void SendPayload(uint8_t port, sendprio_t prio) { void SendPayload(uint8_t port, sendprio_t prio) {

View File

@ -6,12 +6,12 @@ static const char TAG[] = __FILE__;
// symbol to display current time source // symbol to display current time source
const char timeSetSymbols[] = {'G', 'R', 'L', '?'}; const char timeSetSymbols[] = {'G', 'R', 'L', '?'};
getExternalTime TimeSourcePtr; // pointer to time source function Ticker timesyncer;
void timeSync() { xTaskNotify(irqHandlerTask, TIMESYNC_IRQ, eSetBits); }
time_t timeProvider(void) { time_t timeProvider(void) {
ESP_LOGD(TAG, "time synched");
time_t t = 0; time_t t = 0;
#ifdef HAS_GPS #ifdef HAS_GPS
@ -33,7 +33,7 @@ time_t timeProvider(void) {
} }
#endif #endif
// kick off asychron lora sync if we have // kick off asychronous lora sync if we have
#if defined HAS_LORA && defined TIME_SYNC_LORA #if defined HAS_LORA && defined TIME_SYNC_LORA
LMIC_requestNetworkTime(user_request_network_time_callback, &userUTCTime); LMIC_requestNetworkTime(user_request_network_time_callback, &userUTCTime);
#endif #endif
@ -101,11 +101,11 @@ void timepulse_start(void) {
void IRAM_ATTR CLOCKIRQ(void) { void IRAM_ATTR CLOCKIRQ(void) {
BaseType_t xHigherPriorityTaskWoken; BaseType_t xHigherPriorityTaskWoken;
time_t t = SyncToPPS(); // calibrates UTC systime, see Time.h SyncToPPS(); // calibrates UTC systime, see Time.h
xHigherPriorityTaskWoken = pdFALSE; xHigherPriorityTaskWoken = pdFALSE;
if (ClockTask != NULL) if (ClockTask != NULL)
xTaskNotifyFromISR(ClockTask, uint32_t(t), eSetBits, xTaskNotifyFromISR(ClockTask, uint32_t(now()), eSetBits,
&xHigherPriorityTaskWoken); &xHigherPriorityTaskWoken);
#if defined GPS_INT || defined RTC_INT #if defined GPS_INT || defined RTC_INT