altos: Switch all main() to return 'int'
[fw/altos] / src / micropeak-v2.0 / ao_micropeak.c
index dd86ba1c70c2368fbbde98da38a7194bc79a8491..f3fbc9f42ca016041026086b88b0e562e84574a0 100644 (file)
@@ -164,6 +164,13 @@ ao_battery_voltage(void)
        return 330 * stm_cal.vrefint_cal / vrefint;
 }
 
+static void
+ao_log_erase(void)
+{
+       uint32_t        pos;
+       for (pos = 0; pos < ao_storage_log_max; pos += ao_storage_block)
+               ao_storage_erase(pos);
+}
 
 uint8_t        ao_on_battery;
 
@@ -186,6 +193,7 @@ ao_micropeak(void)
 #if BOOST_DELAY
        ao_delay(BOOST_DELAY);
 #endif
+       ao_log_erase();
 
        ao_microflight();
 
@@ -239,9 +247,7 @@ ao_log_delete(void)
 
        /* Look for the flight log matching the requested flight */
        if (cmd_flight == 1 && ao_log_present()) {
-               uint32_t        pos;
-               for (pos = 0; pos < ao_storage_log_max; pos += ao_storage_block)
-                       ao_storage_erase(pos);
+               ao_log_erase();
                puts("Erased");
                return;
        }
@@ -266,9 +272,6 @@ ao_hsi_init(void)
        /* Enable prefetch */
        stm_flash.acr |= (1 << STM_FLASH_ACR_PRFTBE);
 
-       /* Enable power interface clock */
-       stm_rcc.apb1enr |= (1 << STM_RCC_APB1ENR_PWREN);
-
        /* HCLK to 48MHz -> AHB prescaler = /1 */
        cfgr = stm_rcc.cfgr;
        cfgr &= ~(STM_RCC_CFGR_HPRE_MASK << STM_RCC_CFGR_HPRE);
@@ -288,7 +291,7 @@ ao_hsi_init(void)
        stm_rcc.csr |= (1 << STM_RCC_CSR_RMVF);
 }
 
-void
+int
 main(void)
 {
        int i;
@@ -308,7 +311,6 @@ main(void)
        ao_led_init();
        ao_task_init();
        ao_timer_init();
-       ao_serial_init();
        stm_moder_set(&stm_gpioa, 2, STM_MODER_OUTPUT);
        ao_dma_init();
        ao_spi_init();
@@ -319,6 +321,12 @@ main(void)
        ao_ms5607_init();
        ao_storage_init();
 
+       /* Let FLITF clock turn off in sleep mode */
+       stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_FLITFEN);
+
+       /* Le SRAM clock turn off in sleep mode */
+       stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_SRAMEN);
+
        if (ao_on_battery) {
                /* On battery power, run the flight code */
                ao_add_task(&mp_task, ao_micropeak, "micropeak");