changeset 407:b11e50415982 Improment_NVM

Bugfix parallel call of external flash functions: read / write calls to external flash were performed from main loop as well as from timer callback. As result the update of devicedata (every10 minutes) could colidate with the writing of log samples during dive (if logging takes longer then 100ms (clear page). To avoid this raise condition logging of devicedata has been moved to background loop
author ideenmodellierer
date Sun, 12 Jan 2020 18:06:59 +0100
parents 439874690f85
children 2fc08a0d1ec3
files Discovery/Inc/data_exchange_main.h Discovery/Src/base.c Discovery/Src/data_exchange_main.c
diffstat 3 files changed, 25 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Inc/data_exchange_main.h	Sun Jan 12 17:57:11 2020 +0100
+++ b/Discovery/Inc/data_exchange_main.h	Sun Jan 12 18:06:59 2020 +0100
@@ -45,6 +45,7 @@
 void DataEX_copy_to_LifeData(_Bool *modeChangeFlag);
 void DataEX_copy_to_deco(void);
 void DateEx_copy_to_dataOut(void);
+void DataEX_merge_deviceData(void);
 uint32_t DataEX_lost_connection_count(void);
 void DataEX_control_connection_while_asking_for_sleep(void);
 uint8_t DataEX_check_RTE_version__needs_update(void);
--- a/Discovery/Src/base.c	Sun Jan 12 17:57:11 2020 +0100
+++ b/Discovery/Src/base.c	Sun Jan 12 18:06:59 2020 +0100
@@ -351,6 +351,7 @@
     uint8_t lastsecond = 0xFF;
 #endif
 
+	SStateList status;
     detectionState_t pitchstate;
     set_globalState( StBoot0 );
     LastButtonPressed = 0;
@@ -477,6 +478,16 @@
             updateMenu();
             ext_flash_write_settings();
         }
+
+        /* check if tasks depending on global state are pending */
+        get_globalStateList(&status);
+        if(status.base == BaseHome)
+        {
+            tMenuEdit_writeSettingsToFlash(); // takes 900 ms!!
+        }
+
+        DataEX_merge_devicedata(); 	/* data is exchanged at startup and every 10 minutes => check if something changed */
+
         deco_loop();
         TriggerButtonAction();
         if(DoDisplayRefresh)							/* set every 100ms by timer interrupt */
@@ -624,8 +635,6 @@
         base_tempLightLevel = TIM_BACKLIGHT_adjust();
         tCCR_tick();
         tHome_tick();
-        if(status.base == BaseHome)
-            tMenuEdit_writeSettingsToFlash(); // takes 900 ms!!
         break;
     case BaseStop:
         DateEx_copy_to_dataOut();
--- a/Discovery/Src/data_exchange_main.c	Sun Jan 12 17:57:11 2020 +0100
+++ b/Discovery/Src/data_exchange_main.c	Sun Jan 12 18:06:59 2020 +0100
@@ -107,7 +107,6 @@
 static void DataEX_check_DeviceData(void);
 
 /* Exported functions --------------------------------------------------------*/
-
 uint8_t DataEX_was_power_on(void)
 {
 	return wasPowerOn;
@@ -149,6 +148,7 @@
 	pStateReal->data_old__lost_connection_to_slave = 0; //initial value
 	data_old__lost_connection_to_slave_counter_temp = 0;
 	data_old__lost_connection_to_slave_counter_total = 0;
+	DeviceDataUpdated = 0;
 
 	memset((void *)&dataOut, 0, sizeof(SDataReceiveFromMaster));
 
@@ -525,7 +525,6 @@
 }
 
 
-
 static void DataEX_helper_set_Unknown_Date_deviceData(SDeviceLine *lineWrite)
 {	
 	RTC_DateTypeDef sdatestructure;
@@ -671,6 +670,7 @@
 		DataEX_helper_copy_deviceData(&DeviceData->hoursOfOperation, &DeviceDataFlash.hoursOfOperation);
 	}
 	
+
 	/* min values */
 	if(DeviceData->temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32)
 	{
@@ -692,6 +692,7 @@
 	SDevice * pDeviceState = stateDeviceGetPointerWrite();
 
 	memcpy(pDeviceState, &dataInDevice->DeviceData[dataInDevice->boolDeviceData], sizeof(SDevice));
+	DeviceDataUpdated = 1;	/* indicate new data to be written to flash by background task (at last op hour count will be updated) */
 }
 
 
@@ -790,7 +791,6 @@
 		if(DataEX_check_header_and_footer_devicedata())
 		{
 			DataEX_copy_to_DeviceData();
-			DataEX_merge_DeviceData_and_store();
 			DataEX_copy_to_VpmRepetitiveData();
 			data_old__lost_connection_to_slave_counter_temp = 0;
 			data_old__lost_connection_to_slave_counter_retry = 0;
@@ -1144,3 +1144,13 @@
 
 	return 1;
 }
+
+void DataEX_merge_devicedata(void)
+{
+	if(DeviceDataUpdated)
+	{
+		DeviceDataUpdated = 0;
+		DataEX_merge_DeviceData_and_store();
+	}
+}
+