diff --git a/src/main.c b/src/main.c --- a/src/main.c +++ b/src/main.c @@ -58,7 +58,7 @@ int main(void) uint8_t state = SYSTEM_GPSACQ; // DEBUG EMZ FIXME - state = SYSTEM_IDLE; +// state = SYSTEM_IDLE; uint32_t gps_polltimer = 0; uint32_t fix_acq_starttime = 0; @@ -92,6 +92,11 @@ int main(void) { if(gps_ison()) { + HAL_GPIO_WritePin(LED_BLUE, 1); + HAL_Delay(50); + HAL_GPIO_WritePin(LED_BLUE, 0); + + gps_update_data(); // If odd minute @@ -143,12 +148,8 @@ int main(void) // Attempt to acquire GPS fix case SYSTEM_GPSACQ: { - blink_rate = BLINK_FAST; - HAL_PWR_EnterSLEEPMode(0, PWR_SLEEPENTRY_WFI); - HAL_PWR_EnterSLEEPMode(0, PWR_SLEEPENTRY_WFI); - HAL_PWR_EnterSLEEPMode(0, PWR_SLEEPENTRY_WFI); - HAL_PWR_EnterSLEEPMode(0, PWR_SLEEPENTRY_WFI); - + //blink_rate = BLINK_FAST; + blink_rate = BLINK_DISABLE; if(!gps_ison()) { @@ -184,16 +185,22 @@ int main(void) last_wspr_tx_time = HAL_GetTick(); // repeat acq/tx cycle after big time delay state = SYSTEM_IDLE; } + else + { + // We're waiting for a GPS fix, might as well sleep and let the GPS get a fix. + // Enter stop mode for 1 second. Blink in the GPS code above. + __sleep_enter_stop(); + } + } break; // Wait for wspr timeslot and start transmitting case SYSTEM_WSPRTX: { - blink_rate = BLINK_MED; - // Wait for wspr countdown timer to expire and go to tx -// if(timeout_expired) -// { + //blink_rate = BLINK_MED; + blink_rate = BLINK_DISABLE; + // If we're after the minute but not more than 2s after the minute, start tx if(HAL_GetTick() >= nextwspr_time) @@ -224,15 +231,18 @@ int main(void) } else { - HAL_PWR_EnterSLEEPMode(0, PWR_SLEEPENTRY_WFI); - HAL_PWR_EnterSLEEPMode(0, PWR_SLEEPENTRY_WFI); - HAL_PWR_EnterSLEEPMode(0, PWR_SLEEPENTRY_WFI); - HAL_PWR_EnterSLEEPMode(0, PWR_SLEEPENTRY_WFI); + HAL_GPIO_WritePin(LED_BLUE, 1); + HAL_Delay(50); + HAL_GPIO_WritePin(LED_BLUE, 0); + HAL_Delay(50); + HAL_GPIO_WritePin(LED_BLUE, 1); + HAL_Delay(50); + HAL_GPIO_WritePin(LED_BLUE, 0); + + // Enter stop mode for 1 second + __sleep_enter_stop(); } - // Schedule next wakeup (maybe 2mins prior to timeslot if no osc trim) - // Next wakeup should enter SYSTEM_GPSACQ state... - } break; } @@ -258,10 +268,10 @@ int main(void) static void __sleep_enter_stop(void) { // Save ms unix timestamp before we enter sleep mode + HAL_SuspendTick(); uint64_t start = rtc_timestamp(); __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); - HAL_SuspendTick(); HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); // Calculate how long we were asleep