Mercurial > public > ostc4
comparison 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 |
comparison
equal
deleted
inserted
replaced
406:439874690f85 | 407:b11e50415982 |
---|---|
105 static uint8_t DataEX_check_header_and_footer_shifted(void); | 105 static uint8_t DataEX_check_header_and_footer_shifted(void); |
106 static uint8_t DataEX_check_header_and_footer_devicedata(void); | 106 static uint8_t DataEX_check_header_and_footer_devicedata(void); |
107 static void DataEX_check_DeviceData(void); | 107 static void DataEX_check_DeviceData(void); |
108 | 108 |
109 /* Exported functions --------------------------------------------------------*/ | 109 /* Exported functions --------------------------------------------------------*/ |
110 | |
111 uint8_t DataEX_was_power_on(void) | 110 uint8_t DataEX_was_power_on(void) |
112 { | 111 { |
113 return wasPowerOn; | 112 return wasPowerOn; |
114 } | 113 } |
115 | 114 |
147 { | 146 { |
148 SDiveState * pStateReal = stateRealGetPointerWrite(); | 147 SDiveState * pStateReal = stateRealGetPointerWrite(); |
149 pStateReal->data_old__lost_connection_to_slave = 0; //initial value | 148 pStateReal->data_old__lost_connection_to_slave = 0; //initial value |
150 data_old__lost_connection_to_slave_counter_temp = 0; | 149 data_old__lost_connection_to_slave_counter_temp = 0; |
151 data_old__lost_connection_to_slave_counter_total = 0; | 150 data_old__lost_connection_to_slave_counter_total = 0; |
151 DeviceDataUpdated = 0; | |
152 | 152 |
153 memset((void *)&dataOut, 0, sizeof(SDataReceiveFromMaster)); | 153 memset((void *)&dataOut, 0, sizeof(SDataReceiveFromMaster)); |
154 | 154 |
155 dataOut.header.checkCode[0] = 0xBB; | 155 dataOut.header.checkCode[0] = 0xBB; |
156 dataOut.header.checkCode[1] = SPI_RX_STATE_OK; | 156 dataOut.header.checkCode[1] = SPI_RX_STATE_OK; |
523 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Date)) | \ | 523 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Date)) | \ |
524 ((uint32_t)inSdatestructure.WeekDay << 13U)); | 524 ((uint32_t)inSdatestructure.WeekDay << 13U)); |
525 } | 525 } |
526 | 526 |
527 | 527 |
528 | |
529 static void DataEX_helper_set_Unknown_Date_deviceData(SDeviceLine *lineWrite) | 528 static void DataEX_helper_set_Unknown_Date_deviceData(SDeviceLine *lineWrite) |
530 { | 529 { |
531 RTC_DateTypeDef sdatestructure; | 530 RTC_DateTypeDef sdatestructure; |
532 RTC_TimeTypeDef stimestructure; | 531 RTC_TimeTypeDef stimestructure; |
533 | 532 |
669 if(DeviceData->hoursOfOperation.value_int32 < DeviceDataFlash.hoursOfOperation.value_int32) | 668 if(DeviceData->hoursOfOperation.value_int32 < DeviceDataFlash.hoursOfOperation.value_int32) |
670 { | 669 { |
671 DataEX_helper_copy_deviceData(&DeviceData->hoursOfOperation, &DeviceDataFlash.hoursOfOperation); | 670 DataEX_helper_copy_deviceData(&DeviceData->hoursOfOperation, &DeviceDataFlash.hoursOfOperation); |
672 } | 671 } |
673 | 672 |
673 | |
674 /* min values */ | 674 /* min values */ |
675 if(DeviceData->temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32) | 675 if(DeviceData->temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32) |
676 { | 676 { |
677 DataEX_helper_copy_deviceData(&DeviceData->temperatureMinimum, &DeviceDataFlash.temperatureMinimum); | 677 DataEX_helper_copy_deviceData(&DeviceData->temperatureMinimum, &DeviceDataFlash.temperatureMinimum); |
678 } | 678 } |
690 { | 690 { |
691 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn; | 691 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn; |
692 SDevice * pDeviceState = stateDeviceGetPointerWrite(); | 692 SDevice * pDeviceState = stateDeviceGetPointerWrite(); |
693 | 693 |
694 memcpy(pDeviceState, &dataInDevice->DeviceData[dataInDevice->boolDeviceData], sizeof(SDevice)); | 694 memcpy(pDeviceState, &dataInDevice->DeviceData[dataInDevice->boolDeviceData], sizeof(SDevice)); |
695 DeviceDataUpdated = 1; /* indicate new data to be written to flash by background task (at last op hour count will be updated) */ | |
695 } | 696 } |
696 | 697 |
697 | 698 |
698 static void DataEX_copy_to_VpmRepetitiveData(void) | 699 static void DataEX_copy_to_VpmRepetitiveData(void) |
699 { | 700 { |
788 if(!DataEX_check_header_and_footer_ok()) | 789 if(!DataEX_check_header_and_footer_ok()) |
789 { | 790 { |
790 if(DataEX_check_header_and_footer_devicedata()) | 791 if(DataEX_check_header_and_footer_devicedata()) |
791 { | 792 { |
792 DataEX_copy_to_DeviceData(); | 793 DataEX_copy_to_DeviceData(); |
793 DataEX_merge_DeviceData_and_store(); | |
794 DataEX_copy_to_VpmRepetitiveData(); | 794 DataEX_copy_to_VpmRepetitiveData(); |
795 data_old__lost_connection_to_slave_counter_temp = 0; | 795 data_old__lost_connection_to_slave_counter_temp = 0; |
796 data_old__lost_connection_to_slave_counter_retry = 0; | 796 data_old__lost_connection_to_slave_counter_retry = 0; |
797 /* Do not yet reset state. Wait till common data has been received in next cycle. Otherwise invalid data may be forwarded for processing */ | 797 /* Do not yet reset state. Wait till common data has been received in next cycle. Otherwise invalid data may be forwarded for processing */ |
798 /* pStateReal->data_old__lost_connection_to_slave = 0; */ | 798 /* pStateReal->data_old__lost_connection_to_slave = 0; */ |
1142 if(dataIn.footer.checkCode[3] != 0xE4) | 1142 if(dataIn.footer.checkCode[3] != 0xE4) |
1143 return 0; | 1143 return 0; |
1144 | 1144 |
1145 return 1; | 1145 return 1; |
1146 } | 1146 } |
1147 | |
1148 void DataEX_merge_devicedata(void) | |
1149 { | |
1150 if(DeviceDataUpdated) | |
1151 { | |
1152 DeviceDataUpdated = 0; | |
1153 DataEX_merge_DeviceData_and_store(); | |
1154 } | |
1155 } | |
1156 |