comparison Discovery/Src/data_exchange_main.c @ 137:9eda5a75c5fd FlipDisplay

Only copy data if data connection to RTE is valid Only abort DMA if resync is not already in progress
author Ideenmodellierer
date Tue, 19 Feb 2019 21:48:32 +0100
parents acc98f5bd8c4
children cc9c18075e00
comparison
equal deleted inserted replaced
136:6ae8ba5683d6 137:9eda5a75c5fd
113 const uint8_t header_correct[4] = {0xBB, 0xCC, 0xCC, 0xBB}; 113 const uint8_t header_correct[4] = {0xBB, 0xCC, 0xCC, 0xBB};
114 const uint8_t header_data[4] = {0xAA, 0x01, 0x01, 0xAA}; 114 const uint8_t header_data[4] = {0xAA, 0x01, 0x01, 0xAA};
115 115
116 /* Private function prototypes -----------------------------------------------*/ 116 /* Private function prototypes -----------------------------------------------*/
117 uint8_t DataEX_check_header_and_footer_ok(void); 117 uint8_t DataEX_check_header_and_footer_ok(void);
118 uint8_t DataEX_check_header_and_footer_shifted(void);
118 uint8_t DataEX_check_header_and_footer_devicedata(void); 119 uint8_t DataEX_check_header_and_footer_devicedata(void);
119 void DataEX_check_DeviceData(void); 120 void DataEX_check_DeviceData(void);
120 121
121 /* Exported functions --------------------------------------------------------*/ 122 /* Exported functions --------------------------------------------------------*/
122 void DataEX_set_update_RTE_not_power_on(void) 123 void DataEX_set_update_RTE_not_power_on(void)
141 /* A wrong footer indicates a communication interrupt. Statemachine is waiting for new data which is not received because no new transmission is triggered */ 142 /* A wrong footer indicates a communication interrupt. Statemachine is waiting for new data which is not received because no new transmission is triggered */
142 /* ==> Abort data exchange to enable a new RX / TX cycle */ 143 /* ==> Abort data exchange to enable a new RX / TX cycle */
143 if(answer == HAL_BUSY) 144 if(answer == HAL_BUSY)
144 { 145 {
145 HAL_SPI_Abort_IT(&cpu2DmaSpi); 146 HAL_SPI_Abort_IT(&cpu2DmaSpi);
146 data_old__lost_connection_to_slave_counter_total = 1000; /* add significant error offset to indicate error causing an abort event */ 147 data_old__lost_connection_to_slave_counter_total += 1000; /* add significant error offset to indicate error causing an abort event */
147 } 148 }
148 data_old__lost_connection_to_slave_counter_total = answer; 149
149 return; 150 return;
150 } 151 }
151 152
152 153
153 uint32_t DataEX_lost_connection_count(void) 154 uint32_t DataEX_lost_connection_count(void)
322 /* one cycle with NotChipSelect true to clear slave spi buffer */ 323 /* one cycle with NotChipSelect true to clear slave spi buffer */
323 324
324 if(data_old__lost_connection_to_slave_counter_temp >= 3) 325 if(data_old__lost_connection_to_slave_counter_temp >= 3)
325 { 326 {
326 data_old__lost_connection_to_slave_counter_temp = 0; 327 data_old__lost_connection_to_slave_counter_temp = 0;
327 HAL_SPI_Abort_IT(&cpu2DmaSpi); 328 if(DataEX_check_header_and_footer_shifted())
328 __HAL_SPI_CLEAR_OVRFLAG(&cpu2DmaSpi); 329 {
330 HAL_SPI_Abort_IT(&cpu2DmaSpi);
331 }
329 data_old__lost_connection_to_slave_counter_retry++; 332 data_old__lost_connection_to_slave_counter_retry++;
330 } 333 }
331 334
332 DataEx_call_helper_requests(); 335 DataEx_call_helper_requests();
333 336
862 dataIn.data[dataIn.boolPressureData].surface_mbar = 999; 865 dataIn.data[dataIn.boolPressureData].surface_mbar = 999;
863 dataIn.data[dataIn.boolPressureData].pressure_mbar = 98971; 866 dataIn.data[dataIn.boolPressureData].pressure_mbar = 98971;
864 dataIn.mode = MODE_DIVE; 867 dataIn.mode = MODE_DIVE;
865 } 868 }
866 869
867 870 if(pStateReal->data_old__lost_connection_to_slave == 0)
868 ambient = dataIn.data[dataIn.boolPressureData].pressure_mbar / 1000.0f; 871 {
869 surface = dataIn.data[dataIn.boolPressureData].surface_mbar / 1000.0f; 872 ambient = dataIn.data[dataIn.boolPressureData].pressure_mbar / 1000.0f;
870 873 surface = dataIn.data[dataIn.boolPressureData].surface_mbar / 1000.0f;
871 density = ((float)( 100 + pSettings->salinity)) / 100.0f; 874
872 meter = (ambient - surface); 875 density = ((float)( 100 + pSettings->salinity)) / 100.0f;
873 meter /= (0.09807f * density); 876 meter = (ambient - surface);
874 877 meter /= (0.09807f * density);
875 878
876 pStateReal->pressure_uTick_old = pStateReal->pressure_uTick_new; 879
877 pStateReal->pressure_uTick_new = dataIn.data[dataIn.boolPressureData].pressure_uTick; 880 pStateReal->pressure_uTick_old = pStateReal->pressure_uTick_new;
878 pStateReal->pressure_uTick_local_new = HAL_GetTick(); 881 pStateReal->pressure_uTick_new = dataIn.data[dataIn.boolPressureData].pressure_uTick;
879 882 pStateReal->pressure_uTick_local_new = HAL_GetTick();
880 if(ambient < (surface + 0.04f)) 883
881 884 if(ambient < (surface + 0.04f))
882 pStateReal->lifeData.dateBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_dr; 885
883 pStateReal->lifeData.timeBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_tr; 886 pStateReal->lifeData.dateBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_dr;
884 887 pStateReal->lifeData.timeBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_tr;
888 }
885 dataOut.setAccidentFlag = 0; 889 dataOut.setAccidentFlag = 0;
886 890
887 //Start of diveMode? 891 //Start of diveMode?
888 if(pStateReal->mode != MODE_DIVE && dataIn.mode == MODE_DIVE) 892 if(pStateReal->mode != MODE_DIVE && dataIn.mode == MODE_DIVE)
889 { 893 {
930 } 934 }
931 else 935 else
932 { 936 {
933 pStateReal->lifeData.depth_meter = meter; 937 pStateReal->lifeData.depth_meter = meter;
934 } 938 }
935 pStateReal->lifeData.temperature_celsius = dataIn.data[dataIn.boolPressureData].temperature; 939
936 pStateReal->lifeData.ascent_rate_meter_per_min = dataIn.data[dataIn.boolPressureData].ascent_rate_meter_per_min; 940 if(pStateReal->data_old__lost_connection_to_slave == 0)
937 if(pStateReal->mode != MODE_DIVE) 941 {
938 pStateReal->lifeData.max_depth_meter = 0; 942 pStateReal->lifeData.temperature_celsius = dataIn.data[dataIn.boolPressureData].temperature;
939 else 943 pStateReal->lifeData.ascent_rate_meter_per_min = dataIn.data[dataIn.boolPressureData].ascent_rate_meter_per_min;
940 { 944 if(pStateReal->mode != MODE_DIVE)
941 if(meter > pStateReal->lifeData.max_depth_meter) 945 pStateReal->lifeData.max_depth_meter = 0;
942 pStateReal->lifeData.max_depth_meter = meter; 946 else
943 } 947 {
944 948 if(meter > pStateReal->lifeData.max_depth_meter)
945 if(dataIn.accidentFlags & ACCIDENT_DECOSTOP) 949 pStateReal->lifeData.max_depth_meter = meter;
946 pStateReal->decoMissed_at_the_end_of_dive = 1; 950 }
947 if(dataIn.accidentFlags & ACCIDENT_CNS) 951
948 pStateReal->cnsHigh_at_the_end_of_dive = 1; 952 if(dataIn.accidentFlags & ACCIDENT_DECOSTOP)
949 953 pStateReal->decoMissed_at_the_end_of_dive = 1;
950 pStateReal->lifeData.dive_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].divetime_seconds; 954 if(dataIn.accidentFlags & ACCIDENT_CNS)
951 pStateReal->lifeData.dive_time_seconds_without_surface_time = (int32_t)dataIn.data[dataIn.boolTimeData].dive_time_seconds_without_surface_time; 955 pStateReal->cnsHigh_at_the_end_of_dive = 1;
952 pStateReal->lifeData.counterSecondsShallowDepth = dataIn.data[dataIn.boolTimeData].counterSecondsShallowDepth; 956
953 pStateReal->lifeData.surface_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].surfacetime_seconds; 957 pStateReal->lifeData.dive_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].divetime_seconds;
954 958 pStateReal->lifeData.dive_time_seconds_without_surface_time = (int32_t)dataIn.data[dataIn.boolTimeData].dive_time_seconds_without_surface_time;
955 959 pStateReal->lifeData.counterSecondsShallowDepth = dataIn.data[dataIn.boolTimeData].counterSecondsShallowDepth;
956 pStateReal->lifeData.compass_heading = dataIn.data[dataIn.boolCompassData].compass_heading; 960 pStateReal->lifeData.surface_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].surfacetime_seconds;
957 if(settingsGetPointer()->FlipDisplay) /* consider that diver is targeting into the opposite direction */ 961
958 { 962
959 pStateReal->lifeData.compass_heading -= 180.0; 963 pStateReal->lifeData.compass_heading = dataIn.data[dataIn.boolCompassData].compass_heading;
960 if (pStateReal->lifeData.compass_heading < 0) pStateReal->lifeData.compass_heading +=360.0; 964 if(settingsGetPointer()->FlipDisplay) /* consider that diver is targeting into the opposite direction */
961 } 965 {
962 966 pStateReal->lifeData.compass_heading -= 180.0;
963 967 if (pStateReal->lifeData.compass_heading < 0) pStateReal->lifeData.compass_heading +=360.0;
964 pStateReal->lifeData.compass_roll = dataIn.data[dataIn.boolCompassData].compass_roll; 968 }
965 pStateReal->lifeData.compass_pitch = dataIn.data[dataIn.boolCompassData].compass_pitch; 969
966 970
967 pStateReal->lifeData.compass_DX_f = dataIn.data[dataIn.boolCompassData].compass_DX_f; 971 pStateReal->lifeData.compass_roll = dataIn.data[dataIn.boolCompassData].compass_roll;
968 pStateReal->lifeData.compass_DY_f = dataIn.data[dataIn.boolCompassData].compass_DY_f; 972 pStateReal->lifeData.compass_pitch = dataIn.data[dataIn.boolCompassData].compass_pitch;
969 pStateReal->lifeData.compass_DZ_f = dataIn.data[dataIn.boolCompassData].compass_DZ_f; 973
970 974 pStateReal->lifeData.compass_DX_f = dataIn.data[dataIn.boolCompassData].compass_DX_f;
971 pStateReal->compass_uTick_old = pStateReal->compass_uTick_new; 975 pStateReal->lifeData.compass_DY_f = dataIn.data[dataIn.boolCompassData].compass_DY_f;
972 pStateReal->compass_uTick_new = dataIn.data[dataIn.boolCompassData].compass_uTick; 976 pStateReal->lifeData.compass_DZ_f = dataIn.data[dataIn.boolCompassData].compass_DZ_f;
973 pStateReal->compass_uTick_local_new = HAL_GetTick(); 977
974 978 pStateReal->compass_uTick_old = pStateReal->compass_uTick_new;
975 pStateReal->lifeData.cns = dataIn.data[dataIn.boolToxicData].cns; 979 pStateReal->compass_uTick_new = dataIn.data[dataIn.boolCompassData].compass_uTick;
976 pStateReal->lifeData.otu = dataIn.data[dataIn.boolToxicData].otu; 980 pStateReal->compass_uTick_local_new = HAL_GetTick();
977 pStateReal->lifeData.no_fly_time_minutes = dataIn.data[dataIn.boolToxicData].no_fly_time_minutes; 981
978 pStateReal->lifeData.desaturation_time_minutes = dataIn.data[dataIn.boolToxicData].desaturation_time_minutes; 982 pStateReal->lifeData.cns = dataIn.data[dataIn.boolToxicData].cns;
979 983 pStateReal->lifeData.otu = dataIn.data[dataIn.boolToxicData].otu;
980 memcpy(pStateReal->lifeData.tissue_nitrogen_bar, dataIn.data[dataIn.boolTisssueData].tissue_nitrogen_bar,sizeof(pStateReal->lifeData.tissue_nitrogen_bar)); 984 pStateReal->lifeData.no_fly_time_minutes = dataIn.data[dataIn.boolToxicData].no_fly_time_minutes;
981 memcpy(pStateReal->lifeData.tissue_helium_bar, dataIn.data[dataIn.boolTisssueData].tissue_helium_bar,sizeof(pStateReal->lifeData.tissue_helium_bar)); 985 pStateReal->lifeData.desaturation_time_minutes = dataIn.data[dataIn.boolToxicData].desaturation_time_minutes;
982 986
983 if(pStateReal->mode == MODE_DIVE) 987 memcpy(pStateReal->lifeData.tissue_nitrogen_bar, dataIn.data[dataIn.boolTisssueData].tissue_nitrogen_bar,sizeof(pStateReal->lifeData.tissue_nitrogen_bar));
984 { 988 memcpy(pStateReal->lifeData.tissue_helium_bar, dataIn.data[dataIn.boolTisssueData].tissue_helium_bar,sizeof(pStateReal->lifeData.tissue_helium_bar));
985 for(int i= 0; i <16; i++) 989
986 { 990 if(pStateReal->mode == MODE_DIVE)
987 pStateReal->vpm.max_crushing_pressure_he[i] = dataIn.data[dataIn.boolCrushingData].max_crushing_pressure_he[i]; 991 {
988 pStateReal->vpm.max_crushing_pressure_n2[i] = dataIn.data[dataIn.boolCrushingData].max_crushing_pressure_n2[i]; 992 for(int i= 0; i <16; i++)
989 pStateReal->vpm.adjusted_critical_radius_he[i] = dataIn.data[dataIn.boolCrushingData].adjusted_critical_radius_he[i]; 993 {
990 pStateReal->vpm.adjusted_critical_radius_n2[i] = dataIn.data[dataIn.boolCrushingData].adjusted_critical_radius_n2[i]; 994 pStateReal->vpm.max_crushing_pressure_he[i] = dataIn.data[dataIn.boolCrushingData].max_crushing_pressure_he[i];
991 } 995 pStateReal->vpm.max_crushing_pressure_n2[i] = dataIn.data[dataIn.boolCrushingData].max_crushing_pressure_n2[i];
992 } 996 pStateReal->vpm.adjusted_critical_radius_he[i] = dataIn.data[dataIn.boolCrushingData].adjusted_critical_radius_he[i];
993 997 pStateReal->vpm.adjusted_critical_radius_n2[i] = dataIn.data[dataIn.boolCrushingData].adjusted_critical_radius_n2[i];
994 /* battery and ambient light sensors 998 }
995 */ 999 }
996 pStateReal->lifeData.ambient_light_level = dataIn.data[dataIn.boolAmbientLightData].ambient_light_level; 1000
997 pStateReal->lifeData.battery_charge = dataIn.data[dataIn.boolBatteryData].battery_charge; 1001 /* battery and ambient light sensors
998 pStateReal->lifeData.battery_voltage = dataIn.data[dataIn.boolBatteryData].battery_voltage; 1002 */
999 1003 pStateReal->lifeData.ambient_light_level = dataIn.data[dataIn.boolAmbientLightData].ambient_light_level;
1004 pStateReal->lifeData.battery_charge = dataIn.data[dataIn.boolBatteryData].battery_charge;
1005 pStateReal->lifeData.battery_voltage = dataIn.data[dataIn.boolBatteryData].battery_voltage;
1006 }
1000 /* now in ext_flash_write_settings() // hw 161027 1007 /* now in ext_flash_write_settings() // hw 161027
1001 * if((pStateReal->lifeData.battery_charge > 1) && !DataEX_was_power_on() && ((uint8_t)(pStateReal->lifeData.battery_charge) != 0x10)) // get rid of 16% (0x10) 1008 * if((pStateReal->lifeData.battery_charge > 1) && !DataEX_was_power_on() && ((uint8_t)(pStateReal->lifeData.battery_charge) != 0x10)) // get rid of 16% (0x10)
1002 * pSettings->lastKnownBatteryPercentage = (uint8_t)(pStateReal->lifeData.battery_charge); 1009 * pSettings->lastKnownBatteryPercentage = (uint8_t)(pStateReal->lifeData.battery_charge);
1003 */ 1010 */
1004 1011
1378 //return LICENCEBONEX; 1385 //return LICENCEBONEX;
1379 } 1386 }
1380 1387
1381 /* Private functions ---------------------------------------------------------*/ 1388 /* Private functions ---------------------------------------------------------*/
1382 1389
1390 /* Check if there is an empty frame providec by RTE (all 0) or even no data provided by RTE (all 0xFF)
1391 * If that is not the case the DMA is somehow not in sync
1392 */
1393 uint8_t DataEX_check_header_and_footer_shifted()
1394 {
1395 uint8_t ret = 1;
1396 if((dataIn.footer.checkCode[0] != 0x00)
1397 && (dataIn.footer.checkCode[1] != 0x00)
1398 && (dataIn.footer.checkCode[2] != 0x00)
1399 && (dataIn.footer.checkCode[3] != 0x00)) { ret = 0; }
1400
1401 if((dataIn.footer.checkCode[0] != 0xff)
1402 && (dataIn.footer.checkCode[1] != 0xff)
1403 && (dataIn.footer.checkCode[2] != 0xff)
1404 && (dataIn.footer.checkCode[3] != 0xff)) { ret = 0; }
1405
1406 return ret;
1407 }
1408
1383 uint8_t DataEX_check_header_and_footer_ok(void) 1409 uint8_t DataEX_check_header_and_footer_ok(void)
1384 { 1410 {
1385 if(dataIn.header.checkCode[0] != 0xA1) 1411 if(dataIn.header.checkCode[0] != 0xA1)
1386 return 0; 1412 return 0;
1387 if(dataIn.header.checkCode[1] != 0xA2) 1413 if(dataIn.header.checkCode[1] != 0xA2)