comparison Discovery/Src/base.c @ 263:a6c0375bc950 IPC_Sync_Improvment_2

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.
author ideenmodellierer
date Sun, 14 Apr 2019 11:38:14 +0200
parents 822416168585
children 2e58a4094770
comparison
equal deleted inserted replaced
252:1b9be6040d82 263:a6c0375bc950
264 TIM_HandleTypeDef TimDemoHandle; /* used in stm32f4xx_it.c too */ 264 TIM_HandleTypeDef TimDemoHandle; /* used in stm32f4xx_it.c too */
265 #endif 265 #endif
266 266
267 uint8_t LastButtonPressed; 267 uint8_t LastButtonPressed;
268 uint32_t LastButtonPressedTick; 268 uint32_t LastButtonPressedTick;
269 uint32_t BaseTick100ms; /* Tick at last 100ms cycle */
269 270
270 /* 271 /*
271 uint32_t time_before; 272 uint32_t time_before;
272 uint32_t time_between; 273 uint32_t time_between;
273 uint32_t time_after; 274 uint32_t time_after;
382 //settingsGetPointer()->bluetoothActive = 0; /* MX_Bluetooth_PowerOff(); unnecessary as part of MX_GPIO_Init() */ 383 //settingsGetPointer()->bluetoothActive = 0; /* MX_Bluetooth_PowerOff(); unnecessary as part of MX_GPIO_Init() */
383 //settingsGetPointer()->compassBearing = 0; 384 //settingsGetPointer()->compassBearing = 0;
384 set_new_settings_missing_in_ext_flash(); // inlcudes update of firmware version 161121 385 set_new_settings_missing_in_ext_flash(); // inlcudes update of firmware version 161121
385 386
386 GFX_init( &pLayerInvisible ); 387 GFX_init( &pLayerInvisible );
387
388 TIM_init();
389 TIM_BACKLIGHT_init(); 388 TIM_BACKLIGHT_init();
390 389
391 /* 390 /*
392 GFX_helper_font_memory_list(&FontT24); 391 GFX_helper_font_memory_list(&FontT24);
393 GFX_helper_font_memory_list(&FontT42); 392 GFX_helper_font_memory_list(&FontT42);
473 settingsGetPointer()->debugModeOnStart = 0; 472 settingsGetPointer()->debugModeOnStart = 0;
474 ext_flash_write_settings(); 473 ext_flash_write_settings();
475 setDebugMode(); 474 setDebugMode();
476 openInfo( StIDEBUG ); 475 openInfo( StIDEBUG );
477 } 476 }
477
478 TIM_init(); /* start cylic 100ms task */
478 479
479 /* @brief main LOOP 480 /* @brief main LOOP
480 * 481 *
481 * this is executed while no IRQ interrupts it 482 * this is executed while no IRQ interrupts it
482 * - deco calculation 483 * - deco calculation
504 TriggerButtonAction(); 505 TriggerButtonAction();
505 if(DoDisplayRefresh) 506 if(DoDisplayRefresh)
506 { 507 {
507 DoDisplayRefresh = 0; 508 DoDisplayRefresh = 0;
508 RefreshDisplay(); 509 RefreshDisplay();
510
511 if(stateUsed == stateRealGetPointer()) /* Handle log entries while in dive mode*/
512 logbook_InitAndWrite();
509 } 513 }
510 514
511 #ifdef DEBUG_RUNTIME 515 #ifdef DEBUG_RUNTIME
512 translateTime(stateUsed->lifeData.timeBinaryFormat, &Stime); 516 translateTime(stateUsed->lifeData.timeBinaryFormat, &Stime);
513 if(lastsecond == 0xFF) 517 if(lastsecond == 0xFF)
559 563
560 SStateList status; 564 SStateList status;
561 uint32_t timeout_in_seconds; 565 uint32_t timeout_in_seconds;
562 uint32_t timeout_limit_Surface_in_seconds; 566 uint32_t timeout_limit_Surface_in_seconds;
563 567
568
569 BaseTick100ms = HAL_GetTick(); /* store start of 100ms cycle */
570
564 _Bool InDiveMode = 0; 571 _Bool InDiveMode = 0;
565 _Bool modeChange = 0; // to exit from menu and logbook 572 _Bool modeChange = 0; // to exit from menu and logbook
566 573
567 if(stateUsed->mode == MODE_DIVE) 574 if(stateUsed->mode == MODE_DIVE)
568 InDiveMode = 1; 575 InDiveMode = 1;
592 //foto session :-) stateSimGetPointerWrite()->lifeData.battery_charge = 99; 599 //foto session :-) stateSimGetPointerWrite()->lifeData.battery_charge = 99;
593 DataEX_copy_to_deco(); 600 DataEX_copy_to_deco();
594 DataEX_call(); 601 DataEX_call();
595 602
596 if(stateUsed == stateSimGetPointer()) 603 if(stateUsed == stateSimGetPointer())
604 {
597 simulation_UpdateLifeData(1); 605 simulation_UpdateLifeData(1);
606 }
607
598 check_warning(); 608 check_warning();
599 if(stateUsed == stateRealGetPointer())
600 logbook_InitAndWrite();
601 updateMiniLiveLogbook(1); 609 updateMiniLiveLogbook(1);
602 timer_UpdateSecond(1); 610 timer_UpdateSecond(1);
603 base_tempLightLevel = TIM_BACKLIGHT_adjust(); 611 base_tempLightLevel = TIM_BACKLIGHT_adjust();
604 tCCR_tick(); 612 tCCR_tick();
605 tHome_tick(); 613 tHome_tick();
1336 HAL_TIM_PWM_Init(&TimBacklightHandle); 1344 HAL_TIM_PWM_Init(&TimBacklightHandle);
1337 1345
1338 sConfig.OCMode = TIM_OCMODE_PWM1; 1346 sConfig.OCMode = TIM_OCMODE_PWM1;
1339 sConfig.OCPolarity = TIM_OCPOLARITY_HIGH; 1347 sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
1340 sConfig.OCFastMode = TIM_OCFAST_DISABLE; 1348 sConfig.OCFastMode = TIM_OCFAST_DISABLE;
1341 sConfig.Pulse = 50 * 6; 1349 sConfig.Pulse = 100; /* Initial brigthness of display */
1342 1350
1343 HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL); 1351 HAL_TIM_PWM_ConfigChannel(&TimBacklightHandle, &sConfig, TIM_BACKLIGHT_CHANNEL);
1344 HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL); 1352 HAL_TIM_PWM_Start(&TimBacklightHandle, TIM_BACKLIGHT_CHANNEL);
1345 } 1353 }
1346 #endif 1354 #endif