GPS Timepulse handling by semaphore
This commit is contained in:
parent
5c7e4ab9e5
commit
1393e47052
@ -101,7 +101,7 @@ extern uint8_t volatile channel; // wifi channel rotation counter
|
|||||||
extern uint16_t volatile macs_total, macs_wifi, macs_ble,
|
extern uint16_t volatile macs_total, macs_wifi, macs_ble,
|
||||||
batt_voltage; // display values
|
batt_voltage; // display values
|
||||||
extern hw_timer_t *sendCycle, *displaytimer;
|
extern hw_timer_t *sendCycle, *displaytimer;
|
||||||
extern SemaphoreHandle_t I2Caccess;
|
extern SemaphoreHandle_t I2Caccess, TimePulse;
|
||||||
extern bool volatile BitsPending;
|
extern bool volatile BitsPending;
|
||||||
|
|
||||||
extern std::set<uint16_t, std::less<uint16_t>, Mallocator<uint16_t>> macs;
|
extern std::set<uint16_t, std::less<uint16_t>, Mallocator<uint16_t>> macs;
|
||||||
|
@ -41,7 +41,7 @@ void doHousekeeping() {
|
|||||||
if ((millis() >= nextRTCTimeSync) && (timeStatus() == timeSet)) {
|
if ((millis() >= nextRTCTimeSync) && (timeStatus() == timeSet)) {
|
||||||
nextRTCTimeSync = millis() + TIME_WRITE_INTERVAL_RTC *
|
nextRTCTimeSync = millis() + TIME_WRITE_INTERVAL_RTC *
|
||||||
60000; // set up next time sync period
|
60000; // set up next time sync period
|
||||||
if (!set_rtctime(now())) // epoch time
|
if (!set_rtctime(now())) // epoch time
|
||||||
ESP_LOGE(TAG, "RTC set time failure");
|
ESP_LOGE(TAG, "RTC set time failure");
|
||||||
else
|
else
|
||||||
ESP_LOGI(TAG, "RTC time updated");
|
ESP_LOGI(TAG, "RTC time updated");
|
||||||
|
@ -90,16 +90,26 @@ time_t tmConvert_t(uint16_t YYYY, uint8_t MM, uint8_t DD, uint8_t hh,
|
|||||||
time_t get_gpstime(void) {
|
time_t get_gpstime(void) {
|
||||||
// never call now() in this function, this would break this function
|
// never call now() in this function, this would break this function
|
||||||
// to use as SyncProvider due to recursive call to now()
|
// to use as SyncProvider due to recursive call to now()
|
||||||
time_t t = 0;
|
|
||||||
|
time_t t;
|
||||||
if ((gps.time.age() < 1500) && (gps.time.isValid())) {
|
if ((gps.time.age() < 1500) && (gps.time.isValid())) {
|
||||||
t = 1 + tmConvert_t(gps.date.year(), gps.date.month(), gps.date.day(),
|
t = tmConvert_t(gps.date.year(), gps.date.month(), gps.date.day(),
|
||||||
gps.time.hour(), gps.time.minute(), gps.time.second());
|
gps.time.hour(), gps.time.minute(), gps.time.second());
|
||||||
ESP_LOGD(TAG, "GPS time: %4d/%02d/%02d %02d:%02d:%02d", year(t), month(t),
|
ESP_LOGD(TAG, "GPS time: %4d/%02d/%02d %02d:%02d:%02d", year(t), month(t),
|
||||||
day(t), hour(t), minute(t), second(t));
|
day(t), hour(t), minute(t), second(t));
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGW(TAG, "GPS has no confident time");
|
ESP_LOGW(TAG, "GPS has no confident time");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return t;
|
|
||||||
|
// sync on top of next second bv timepulse
|
||||||
|
if (xSemaphoreTake(TimePulse, pdMS_TO_TICKS(1000)) == pdTRUE)
|
||||||
|
return t;
|
||||||
|
else {
|
||||||
|
ESP_LOGW(TAG, "No GPS timepulse, thus time can't be synced by GPS");
|
||||||
|
return 0;
|
||||||
|
} // failure
|
||||||
|
|
||||||
} // get_gpstime()
|
} // get_gpstime()
|
||||||
|
|
||||||
// GPS serial feed FreeRTos Task
|
// GPS serial feed FreeRTos Task
|
||||||
|
@ -73,7 +73,7 @@ hw_timer_t *displaytimer = NULL;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
TaskHandle_t irqHandlerTask;
|
TaskHandle_t irqHandlerTask;
|
||||||
SemaphoreHandle_t I2Caccess;
|
SemaphoreHandle_t I2Caccess, TimePulse;
|
||||||
|
|
||||||
// container holding unique MAC address hashes with Memory Alloctor using PSRAM,
|
// container holding unique MAC address hashes with Memory Alloctor using PSRAM,
|
||||||
// if present
|
// if present
|
||||||
@ -99,7 +99,12 @@ void setup() {
|
|||||||
|
|
||||||
I2Caccess = xSemaphoreCreateMutex(); // for access management of i2c bus
|
I2Caccess = xSemaphoreCreateMutex(); // for access management of i2c bus
|
||||||
if (I2Caccess)
|
if (I2Caccess)
|
||||||
xSemaphoreGive((I2Caccess)); // Flag the i2c bus available for use
|
xSemaphoreGive(I2Caccess); // Flag the i2c bus available for use
|
||||||
|
|
||||||
|
TimePulse = xSemaphoreCreateMutex(); // for time pulse flip
|
||||||
|
if (TimePulse)
|
||||||
|
xSemaphoreTake(TimePulse, (TickType_t)10);
|
||||||
|
// Block TimePulse since we have no pulse yet
|
||||||
|
|
||||||
// disable brownout detection
|
// disable brownout detection
|
||||||
#ifdef DISABLE_BROWNOUT
|
#ifdef DISABLE_BROWNOUT
|
||||||
|
@ -191,5 +191,8 @@ time_t sync_clock(time_t t) {
|
|||||||
// timer
|
// timer
|
||||||
void IRAM_ATTR CLOCKIRQ() {
|
void IRAM_ATTR CLOCKIRQ() {
|
||||||
xTaskNotifyFromISR(ClockTask, xTaskGetTickCountFromISR(), eSetBits, NULL);
|
xTaskNotifyFromISR(ClockTask, xTaskGetTickCountFromISR(), eSetBits, NULL);
|
||||||
|
#ifdef GPS_INT
|
||||||
|
xSemaphoreGiveFromISR(TimePulse, NULL);
|
||||||
|
#endif
|
||||||
portYIELD_FROM_ISR();
|
portYIELD_FROM_ISR();
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user