diff Discovery/Src/data_exchange_main.c @ 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 3f7d80f37bfc
line wrap: on
line diff
--- 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();
+	}
+}
+