# HG changeset patch # User ideenmodellierer # Date 1555234694 -7200 # Node ID a6c0375bc95013f2572ec008339d40f598f00187 # Parent 1b9be6040d8279117c7fc99d528790611638f10b Forward 100ms time stamp to RTE and handle logbook in main loop Because of code execution variance between 100ms cycle event and start of SPI communication, the synchronization between Main and RTE may shift. To avoid these shifts the time stamp of the 100ms event is forwarded to the RTE which is now able to adapt to small variations. One variation point was the storage of dive samples within the external flash. Taking a closer look how this function works, moving it from the timer callback to the main loop should not be an issue. A critical point of having the function in the timer call back was the sector clean function which is called (depending on dive data) every ~300minutes and may take 250ms - 1500ms. diff -r 1b9be6040d82 -r a6c0375bc950 Common/Inc/global_constants.h --- a/Common/Inc/global_constants.h Sat Apr 13 14:36:33 2019 +0200 +++ b/Common/Inc/global_constants.h Sun Apr 14 11:38:14 2019 +0200 @@ -42,7 +42,7 @@ /* Define INDEX for information exchanged within the header */ #define SPI_HEADER_INDEX_RX_STATE (1) -#define SPI_HEADER_INDEX_FRAME_CNT (2) +#define SPI_HEADER_INDEX_TX_TICK (2) #define SPI_RX_STATE_OK (0) #define SPI_RX_STATE_SHIFTED (1) diff -r 1b9be6040d82 -r a6c0375bc950 Discovery/Src/base.c --- a/Discovery/Src/base.c Sat Apr 13 14:36:33 2019 +0200 +++ b/Discovery/Src/base.c Sun Apr 14 11:38:14 2019 +0200 @@ -266,6 +266,7 @@ uint8_t LastButtonPressed; uint32_t LastButtonPressedTick; +uint32_t BaseTick100ms; /* Tick at last 100ms cycle */ /* uint32_t time_before; @@ -384,8 +385,6 @@ set_new_settings_missing_in_ext_flash(); // inlcudes update of firmware version 161121 GFX_init( &pLayerInvisible ); - - TIM_init(); TIM_BACKLIGHT_init(); /* @@ -476,6 +475,8 @@ openInfo( StIDEBUG ); } + TIM_init(); /* start cylic 100ms task */ + /* @brief main LOOP * * this is executed while no IRQ interrupts it @@ -506,6 +507,9 @@ { DoDisplayRefresh = 0; RefreshDisplay(); + + if(stateUsed == stateRealGetPointer()) /* Handle log entries while in dive mode*/ + logbook_InitAndWrite(); } #ifdef DEBUG_RUNTIME @@ -561,6 +565,9 @@ uint32_t timeout_in_seconds; uint32_t timeout_limit_Surface_in_seconds; + + BaseTick100ms = HAL_GetTick(); /* store start of 100ms cycle */ + _Bool InDiveMode = 0; _Bool modeChange = 0; // to exit from menu and logbook @@ -594,10 +601,11 @@ DataEX_call(); if(stateUsed == stateSimGetPointer()) + { simulation_UpdateLifeData(1); + } + check_warning(); - if(stateUsed == stateRealGetPointer()) - logbook_InitAndWrite(); updateMiniLiveLogbook(1); timer_UpdateSecond(1); base_tempLightLevel = TIM_BACKLIGHT_adjust(); @@ -1338,7 +1346,7 @@ sConfig.OCMode = TIM_OCMODE_PWM1; sConfig.OCPolarity = TIM_OCPOLARITY_HIGH; sConfig.OCFastMode = TIM_OCFAST_DISABLE; - sConfig.Pulse = 50 * 6; + sConfig.Pulse = 100; /* Initial brigthness of display */ HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL); HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL);