comparison Small_CPU/Src/scheduler.c @ 135:5df4f1a315cb FlipDisplay

Restore old data copy locations Do first calculation based on ambient bar to avoid desaturation shift Added error handling for lost communication
author Ideenmodellierer
date Tue, 19 Feb 2019 18:18:37 +0100
parents 6347a86caa18
children 69f4b8067daa
comparison
equal deleted inserted replaced
134:0586ae83a243 135:5df4f1a315cb
42 #include "decom.h" 42 #include "decom.h"
43 #include "wireless.h" 43 #include "wireless.h"
44 #include "tm_stm32f4_otp.h" 44 #include "tm_stm32f4_otp.h"
45 45
46 46
47 #define INVALID_PREASURE_VALUE (100.0F)
48
47 /* Private types -------------------------------------------------------------*/ 49 /* Private types -------------------------------------------------------------*/
48 const SGas Air = {79,0,0,0,0}; 50 const SGas Air = {79,0,0,0,0};
49 51
50 uint8_t testarrayindex = 0; 52 uint8_t testarrayindex = 0;
51 uint32_t testarray[256]; 53 uint32_t testarray[256];
121 global.ButtonPICdata[2] = 0xFF; 123 global.ButtonPICdata[2] = 0xFF;
122 global.ButtonPICdata[3] = 0xFF; 124 global.ButtonPICdata[3] = 0xFF;
123 125
124 global.I2C_SystemStatus = 0xFF; // 0x00 would be everything working 126 global.I2C_SystemStatus = 0xFF; // 0x00 would be everything working
125 127
126 global.lifeData.pressure_ambient_bar = 1.0f; 128 global.lifeData.pressure_ambient_bar = INVALID_PREASURE_VALUE;
127 global.lifeData.pressure_surface_bar = 1.0f; 129 global.lifeData.pressure_surface_bar = INVALID_PREASURE_VALUE;
128 decom_reset_with_1000mbar(&global.lifeData); 130 decom_reset_with_1000mbar(&global.lifeData);
129 131
130 global.demo_mode = 0; 132 global.demo_mode = 0;
131 133
132 for(int i = 0; i < MAX_SENSORS; i++) 134 for(int i = 0; i < MAX_SENSORS; i++)
285 MX_I2C1_Init(); 287 MX_I2C1_Init();
286 // init_pressure(); 288 // init_pressure();
287 // compass_init(0, 7); 289 // compass_init(0, 7);
288 // accelerator_init(); 290 // accelerator_init();
289 } 291 }
290 //Collect and copy sensor data just in one place.
291 //TODO: compass_calib_common needs big refactor.
292 compass_read();
293 acceleration_read();
294 compass_calc();
295 pressure_update();
296 copyPressureData();
297 battery_gas_gauge_get_data();
298 copyCompassData();
299 // copyCnsAndOtuData(); //TODO: move here.
300 copyTimeData();
301 // copyBatteryData(); // TODO: move here.
302 copyDeviceData();
303 copyVpmCrushingData();
304 //
305 scheduleUpdateDeviceData();
306
307
308 } 292 }
309 293
310 294
311 /** 295 /**
312 ****************************************************************************** 296 ******************************************************************************
437 * @author heinrichs weikamp gmbh 421 * @author heinrichs weikamp gmbh
438 * @version V0.0.2 422 * @version V0.0.2
439 * @date 18-June-2015 423 * @date 18-June-2015
440 ****************************************************************************** 424 ******************************************************************************
441 */ 425 */
426
442 void schedule_check_resync(void) 427 void schedule_check_resync(void)
443 { 428 {
444 //TODO: REMOVE 429 //TODO: REMOVE
445 if((global.check_sync_not_running >= 2)) 430 if((global.check_sync_not_running >= 3))
446 { 431 {
447 // global.dataSendToSlaveIsNotValidCount = 0; 432 // global.dataSendToSlaveIsNotValidCount = 0;
448 // global.check_sync_not_running = 0; 433 global.check_sync_not_running = 0;
449 // global.sync_error_count++; 434 global.sync_error_count++;
450 // MX_SPI_DeInit(); 435
451 // HAL_Delay(30); /* could be closer to length of data transmission 23.Feb.2015 hw */ 436 /* Try to start communication again. If exchange is stuck during execution for some reason the TX will be aborted by the
452 // MX_DMA_Init(); 437 * function error handler
453 // MX_SPI1_Init(); 438 */
454 // SPI_Start_single_TxRx_with_Master(); 439 SPI_Start_single_TxRx_with_Master();
455 } 440 }
456 } 441 }
457 442
458 443
459 /** 444 /**
510 495
511 //Evaluate pressure at 20 ms, 120 ms, 220 ms,.... 496 //Evaluate pressure at 20 ms, 120 ms, 220 ms,....
512 if(ticksdiff >= counterPressure100msec * 100 + 20) 497 if(ticksdiff >= counterPressure100msec * 100 + 20)
513 { 498 {
514 global.check_sync_not_running++; 499 global.check_sync_not_running++;
515 // pressure_update(); 500 pressure_update();
516 // scheduleUpdateDeviceData(); 501 scheduleUpdateDeviceData();
517 if(global.demo_mode) 502 if(global.demo_mode)
518 { 503 {
519 turbo_seconds = demo_modify_temperature_and_pressure(global.lifeData.dive_time_seconds, counterPressure100msec, global.ceiling_from_main_CPU_mbar); 504 turbo_seconds = demo_modify_temperature_and_pressure(global.lifeData.dive_time_seconds, counterPressure100msec, global.ceiling_from_main_CPU_mbar);
520 if(turbo_seconds) 505 if(turbo_seconds)
521 { 506 {
542 counterAscentRate = 0; 527 counterAscentRate = 0;
543 528
544 // if(global.demo_mode) 529 // if(global.demo_mode)
545 // global.lifeData.ascent_rate_meter_per_min /= 4; 530 // global.lifeData.ascent_rate_meter_per_min /= 4;
546 } 531 }
547 // copyPressureData(); 532 copyPressureData();
548 counterPressure100msec++; 533 counterPressure100msec++;
549 } 534 }
550 //evaluate compass data at 50 ms, 150 ms, 250 ms,.... 535 //evaluate compass data at 50 ms, 150 ms, 250 ms,....
551 // if(ticksdiff >= counterCompass100msec * 100 + 50) 536 if(ticksdiff >= counterCompass100msec * 100 + 50)
552 // { 537 {
553 // compass_read(); 538 compass_read();
554 // acceleration_read(); 539 acceleration_read();
555 // compass_calc(); 540 compass_calc();
556 // copyCompassData(); 541 copyCompassData();
557 // counterCompass100msec++; 542 counterCompass100msec++;
558 // } 543 }
559 544
560 if(ticksdiff >= counterAmbientLight100msec * 100 + 70) 545 if(ticksdiff >= counterAmbientLight100msec * 100 + 70)
561 { 546 {
562 adc_ambient_light_sensor_get_data(); 547 adc_ambient_light_sensor_get_data();
563 copyAmbientLightData(); 548 copyAmbientLightData();
720 //Evaluate pressure at 20 ms, 120 ms, 220 ms,... 705 //Evaluate pressure at 20 ms, 120 ms, 220 ms,...
721 if(ticksdiff >= counterPressure100msec * 100 + 20) 706 if(ticksdiff >= counterPressure100msec * 100 + 20)
722 { 707 {
723 global.check_sync_not_running++; 708 global.check_sync_not_running++;
724 709
725 //pressure_update(); 710 pressure_update();
726 //scheduleUpdateDeviceData(); 711 scheduleUpdateDeviceData();
727 global.lifeData.ascent_rate_meter_per_min = 0; 712 global.lifeData.ascent_rate_meter_per_min = 0;
728 //copyPressureData(); 713 copyPressureData();
729 714
730 if(temperature_carousel > 20.0f) 715 if(temperature_carousel > 20.0f)
731 { 716 {
732 temperature_carousel = 20.0f; 717 temperature_carousel = 20.0f;
733 temperature_changer = -0.1f; 718 temperature_changer = -0.1f;
802 787
803 //Evaluate pressure at 20 ms, 120 ms, 220 ms,... 788 //Evaluate pressure at 20 ms, 120 ms, 220 ms,...
804 if(ticksdiff >= counterPressure100msec * 100 + 20) 789 if(ticksdiff >= counterPressure100msec * 100 + 20)
805 { 790 {
806 global.check_sync_not_running++; 791 global.check_sync_not_running++;
807 // pressure_update(); 792 pressure_update();
808 // scheduleUpdateDeviceData(); 793 scheduleUpdateDeviceData();
809 global.lifeData.ascent_rate_meter_per_min = 0; 794 global.lifeData.ascent_rate_meter_per_min = 0;
810 // copyPressureData(); 795 copyPressureData();
811 counterPressure100msec++; 796 counterPressure100msec++;
812 797
813 if(scheduleCheck_pressure_reached_dive_mode_level()) 798 if(scheduleCheck_pressure_reached_dive_mode_level())
814 global.mode = MODE_DIVE; 799 global.mode = MODE_DIVE;
815 } 800 }
816 801
817 //evaluate compass data at 50 ms, 150 ms, 250 ms,... 802 //evaluate compass data at 50 ms, 150 ms, 250 ms,...
818 803
819 // if(ticksdiff >= counterCompass100msec * 100 + 50) 804 if(ticksdiff >= counterCompass100msec * 100 + 50)
820 // { 805 {
821 //// compass_read(); 806 compass_read();
822 //// acceleration_read(); 807 acceleration_read();
823 // compass_calc(); 808 compass_calc();
824 // copyCompassData(); 809 copyCompassData();
825 // counterCompass100msec++; 810 counterCompass100msec++;
826 // } 811 }
827 812
828 //evaluate compass data at 70 ms, 170 ms, 270 ms,... 813 //evaluate compass data at 70 ms, 170 ms, 270 ms,...
829 if(ticksdiff >= counterAmbientLight100msec * 100 + 70) 814 if(ticksdiff >= counterAmbientLight100msec * 100 + 70)
830 { 815 {
831 adc_ambient_light_sensor_get_data(); 816 adc_ambient_light_sensor_get_data();
845 global.accidentFlag = 0; 830 global.accidentFlag = 0;
846 global.accidentRemainingSeconds = 0; 831 global.accidentRemainingSeconds = 0;
847 vpm_init(&global.vpm, global.conservatism, global.repetitive_dive, global.seconds_since_last_dive); 832 vpm_init(&global.vpm, global.conservatism, global.repetitive_dive, global.seconds_since_last_dive);
848 clearDecoNow = 0; 833 clearDecoNow = 0;
849 } 834 }
850 835
851 //Set back tick counter 836 //Set back tick counter
852 tickstart = HAL_GetTick(); 837 tickstart = HAL_GetTick();
853 838
854 839
855 if(global.seconds_since_last_dive) 840 if(global.seconds_since_last_dive)
870 855
871 update_surface_pressure(1); 856 update_surface_pressure(1);
872 scheduleUpdateLifeData(0); 857 scheduleUpdateLifeData(0);
873 decom_oxygen_calculate_otu_degrade(&global.lifeData.otu, global.seconds_since_last_dive); 858 decom_oxygen_calculate_otu_degrade(&global.lifeData.otu, global.seconds_since_last_dive);
874 decom_oxygen_calculate_cns_degrade(&global.lifeData.cns, global.seconds_since_last_dive); 859 decom_oxygen_calculate_cns_degrade(&global.lifeData.cns, global.seconds_since_last_dive);
875 global.lifeData.desaturation_time_minutes = decom_calc_desaturation_time(global.lifeData.tissue_nitrogen_bar,global.lifeData.tissue_helium_bar,global.lifeData.pressure_surface_bar); 860
861 /* start desaturation calculation after first valid measurement has been done */
862 if(global.lifeData.pressure_surface_bar != INVALID_PREASURE_VALUE)
863 {
864 global.lifeData.desaturation_time_minutes = decom_calc_desaturation_time(global.lifeData.tissue_nitrogen_bar,global.lifeData.tissue_helium_bar,global.lifeData.pressure_surface_bar);
865 }
866 else
867 {
868 global.lifeData.desaturation_time_minutes = 0;
869 }
876 battery_charger_get_status_and_contral_battery_gas_gauge(0); 870 battery_charger_get_status_and_contral_battery_gas_gauge(0);
877 battery_gas_gauge_get_data(); 871 battery_gas_gauge_get_data();
878 872
879 copyCnsAndOtuData(); 873 copyCnsAndOtuData();
880 copyTimeData(); 874 copyTimeData();
889 if(!is_init_pressure_done()) 883 if(!is_init_pressure_done())
890 { 884 {
891 init_pressure(); 885 init_pressure();
892 } 886 }
893 } 887 }
894 888
895 counterCompass100msec = 0; 889 counterCompass100msec = 0;
896 counterPressure100msec = 0; 890 counterPressure100msec = 0;
897 counterAmbientLight100msec = 0; 891 counterAmbientLight100msec = 0;
898 counterWireless1msec = 0; 892 counterWireless1msec = 0;
899 } 893 }
1058 uint32_t ticksdiff = 0; 1052 uint32_t ticksdiff = 0;
1059 uint32_t ticksnow = 0; 1053 uint32_t ticksnow = 0;
1060 uint32_t time_seconds = 0; 1054 uint32_t time_seconds = 0;
1061 uint8_t whichGasTmp = 0; 1055 uint8_t whichGasTmp = 0;
1062 1056
1057 uint8_t updateTissueData = 0;
1058
1059
1060 if(global.lifeData.pressure_surface_bar == INVALID_PREASURE_VALUE)
1061 {
1062 updateTissueData = 1;
1063 }
1064
1063 if(asynchron_milliseconds_since_last < 0) 1065 if(asynchron_milliseconds_since_last < 0)
1064 { 1066 {
1065 first = 1; 1067 first = 1;
1066 tickstart = 0; 1068 tickstart = 0;
1067 ticksrest = 0; 1069 ticksrest = 0;
1077 1079
1078 whichGasTmp = global.whichGas; 1080 whichGasTmp = global.whichGas;
1079 global.lifeData.actualGas = global.aktualGas[whichGasTmp]; 1081 global.lifeData.actualGas = global.aktualGas[whichGasTmp];
1080 global.lifeData.pressure_ambient_bar = get_pressure_mbar() / 1000.0f; 1082 global.lifeData.pressure_ambient_bar = get_pressure_mbar() / 1000.0f;
1081 global.lifeData.pressure_surface_bar = get_surface_mbar() / 1000.0f; 1083 global.lifeData.pressure_surface_bar = get_surface_mbar() / 1000.0f;
1084
1085 if(updateTissueData)
1086 {
1087 decom_reset_with_ambientmbar(global.lifeData.pressure_surface_bar,&global.lifeData);
1088 }
1082 1089
1083 if(!asynchron_milliseconds_since_last) 1090 if(!asynchron_milliseconds_since_last)
1084 { 1091 {
1085 ticksnow = HAL_GetTick(); 1092 ticksnow = HAL_GetTick();
1086 ticksdiff = time_elapsed_ms(tickstart,ticksnow); 1093 ticksdiff = time_elapsed_ms(tickstart,ticksnow);