comparison Small_CPU/Src/scheduler.c @ 88:3db7389d49cc kittz

revert
author Dmitry Romanov <kitt@bk.ru>
date Thu, 22 Nov 2018 12:02:55 +0300
parents e746bf846638
children ff7775cc34c4
comparison
equal deleted inserted replaced
87:e746bf846638 88:3db7389d49cc
108 global.conservatism = 0; 108 global.conservatism = 0;
109 global.whichGas = 0; 109 global.whichGas = 0;
110 global.aktualGas[0] = Air; 110 global.aktualGas[0] = Air;
111 global.lifeData.actualGas = global.aktualGas[0]; 111 global.lifeData.actualGas = global.aktualGas[0];
112 112
113 const uint8_t button_standard_sensitivity = ((2400-( 90 *24))/10)+15; 113 const uint8_t button_standard_sensitivity = ((2400-( 40 *24))/10)+15;
114 global.ButtonResponsiveness[0] = button_standard_sensitivity; 114 global.ButtonResponsiveness[0] = button_standard_sensitivity;
115 global.ButtonResponsiveness[1] = button_standard_sensitivity; 115 global.ButtonResponsiveness[1] = button_standard_sensitivity;
116 global.ButtonResponsiveness[2] = button_standard_sensitivity; 116 global.ButtonResponsiveness[2] = button_standard_sensitivity;
117 global.ButtonResponsiveness[3] = button_standard_sensitivity; 117 global.ButtonResponsiveness[3] = button_standard_sensitivity;
118 118
179 } 179 }
180 180
181 181
182 void scheduleSpecial_Evaluate_DataSendToSlave(void) 182 void scheduleSpecial_Evaluate_DataSendToSlave(void)
183 { 183 {
184 184 global.dataSendToSlavePending = 0;
185 /* for device data updates */ 185 if(!global.dataSendToSlaveIsValid) return;
186 deviceDataFlashValid = 0;
187 memcpy(&DeviceDataFlash, &global.dataSendToSlave.data.DeviceData, sizeof(SDevice));
188
189 //TODO: (kittz) split by current mode.
190
191 // new hw 170523
192 if(global.I2C_SystemStatus != HAL_OK)
193 {
194 MX_I2C1_TestAndClear();
195 MX_I2C1_Init();
196 if(!is_init_pressure_done())
197 {
198 init_pressure();
199 }
200 }
201
202 pressure_update();
203 copyPressureData();
204 compass_read();
205 acceleration_read();
206 compass_calc();
207 battery_gas_gauge_get_data();
208 copyCompassData();
209
210 copyCnsAndOtuData();
211 copyTimeData();
212 copyBatteryData();
213 copyDeviceData();
214 copyVpmCrushingData();
215
216 deviceDataFlashValid = 1;
217 scheduleUpdateDeviceData();
218
219
220
221
222 // global.dataSendToSlavePending = 0;
223 // if(!global.dataSendToSlaveIsValid) return; //TODO: WHAT THE FUCK?????!!!!!
224 186
225 global.dataSendToMaster.confirmRequest.uw = 0; 187 global.dataSendToMaster.confirmRequest.uw = 0;
226 188
227 if(TM_OTP_Read(0,0) == 0xFF) 189 if(TM_OTP_Read(0,0) == 0xFF)
228 { 190 {
301 } 263 }
302 264
303 /* for simulation / testing */ 265 /* for simulation / testing */
304 global.ceiling_from_main_CPU_mbar = global.dataSendToSlave.data.ambient_pressure_mbar_ceiling; 266 global.ceiling_from_main_CPU_mbar = global.dataSendToSlave.data.ambient_pressure_mbar_ceiling;
305 267
306 268 /* for device data updates */
269 deviceDataFlashValid = 0;
270 memcpy(&DeviceDataFlash, &global.dataSendToSlave.data.DeviceData, sizeof(SDevice));
271 deviceDataFlashValid = 1;
307 } 272 }
308 273
309 274
310 /** 275 /**
311 ****************************************************************************** 276 ******************************************************************************
509 474
510 //Evaluate pressure at 20 ms, 120 ms, 220 ms,.... 475 //Evaluate pressure at 20 ms, 120 ms, 220 ms,....
511 if(ticksdiff >= counterPressure100msec * 100 + 20) 476 if(ticksdiff >= counterPressure100msec * 100 + 20)
512 { 477 {
513 global.check_sync_not_running++; 478 global.check_sync_not_running++;
514 // pressure_update(); 479 pressure_update();
515 // scheduleUpdateDeviceData(); 480 scheduleUpdateDeviceData();
516 if(global.demo_mode) 481 if(global.demo_mode)
517 { 482 {
518 turbo_seconds = demo_modify_temperature_and_pressure(global.lifeData.dive_time_seconds, counterPressure100msec, global.ceiling_from_main_CPU_mbar); 483 turbo_seconds = demo_modify_temperature_and_pressure(global.lifeData.dive_time_seconds, counterPressure100msec, global.ceiling_from_main_CPU_mbar);
519 if(turbo_seconds) 484 if(turbo_seconds)
520 { 485 {
541 counterAscentRate = 0; 506 counterAscentRate = 0;
542 507
543 // if(global.demo_mode) 508 // if(global.demo_mode)
544 // global.lifeData.ascent_rate_meter_per_min /= 4; 509 // global.lifeData.ascent_rate_meter_per_min /= 4;
545 } 510 }
546 // copyPressureData(); 511 copyPressureData();
547 counterPressure100msec++; 512 counterPressure100msec++;
548 } 513 }
549 //evaluate compass data at 50 ms, 150 ms, 250 ms,.... 514 //evaluate compass data at 50 ms, 150 ms, 250 ms,....
550 if(ticksdiff >= counterCompass100msec * 100 + 50) 515 if(ticksdiff >= counterCompass100msec * 100 + 50)
551 { 516 {
552 // compass_read(); 517 compass_read();
553 // acceleration_read(); 518 acceleration_read();
554 // compass_calc(); 519 compass_calc();
555 // copyCompassData(); 520 copyCompassData();
556 counterCompass100msec++; 521 counterCompass100msec++;
557 } 522 }
558 523
559 if(ticksdiff >= counterAmbientLight100msec * 100 + 70) 524 if(ticksdiff >= counterAmbientLight100msec * 100 + 70)
560 { 525 {
578 scheduleUpdateLifeData(0); // includes tissues 543 scheduleUpdateLifeData(0); // includes tissues
579 global.lifeData.dive_time_seconds++; // there is dive_time_seconds_without_surface_time too 544 global.lifeData.dive_time_seconds++; // there is dive_time_seconds_without_surface_time too
580 global.lifeData.ppO2 = decom_calc_ppO2(global.lifeData.pressure_ambient_bar, &global.lifeData.actualGas); 545 global.lifeData.ppO2 = decom_calc_ppO2(global.lifeData.pressure_ambient_bar, &global.lifeData.actualGas);
581 decom_oxygen_calculate_cns(&global.lifeData.cns,global.lifeData.ppO2); 546 decom_oxygen_calculate_cns(&global.lifeData.cns,global.lifeData.ppO2);
582 decom_oxygen_calculate_otu(&global.lifeData.otu,global.lifeData.ppO2); 547 decom_oxygen_calculate_otu(&global.lifeData.otu,global.lifeData.ppO2);
583 // battery_gas_gauge_get_data(); 548 battery_gas_gauge_get_data();
584 549
585 550
586 /** counter_exit allows safe exit via button for testing 551 /** counter_exit allows safe exit via button for testing
587 * and demo_mode is exited too if aplicable. 552 * and demo_mode is exited too if aplicable.
588 */ 553 */
650 global.lifeData.counterSecondsShallowDepth = 0; 615 global.lifeData.counterSecondsShallowDepth = 0;
651 global.lifeData.dive_time_seconds_without_surface_time++; 616 global.lifeData.dive_time_seconds_without_surface_time++;
652 } 617 }
653 } // standard dive or DIVEMODE_Apnea 618 } // standard dive or DIVEMODE_Apnea
654 619
655 // copyVpmCrushingData(); 620 copyVpmCrushingData();
656 // copyTimeData(); 621 copyTimeData();
657 // copyCnsAndOtuData(); 622 copyCnsAndOtuData();
658 // copyBatteryData(); 623 copyBatteryData();
659 624
660 // // new hw 170523 625 // new hw 170523
661 // if(global.I2C_SystemStatus != HAL_OK) 626 if(global.I2C_SystemStatus != HAL_OK)
662 // { 627 {
663 // MX_I2C1_TestAndClear(); 628 MX_I2C1_TestAndClear();
664 // MX_I2C1_Init(); 629 MX_I2C1_Init();
665 // if(!is_init_pressure_done()) 630 if(!is_init_pressure_done())
666 // { 631 {
667 // init_pressure(); 632 init_pressure();
668 // } 633 }
669 // } 634 }
670 635
671 counterCompass100msec = 0; 636 counterCompass100msec = 0;
672 counterPressure100msec = 0; 637 counterPressure100msec = 0;
673 counterAmbientLight100msec = 0; 638 counterAmbientLight100msec = 0;
674 counterWireless1msec = 0; 639 counterWireless1msec = 0;
719 //Evaluate pressure at 20 ms, 120 ms, 220 ms,... 684 //Evaluate pressure at 20 ms, 120 ms, 220 ms,...
720 if(ticksdiff >= counterPressure100msec * 100 + 20) 685 if(ticksdiff >= counterPressure100msec * 100 + 20)
721 { 686 {
722 global.check_sync_not_running++; 687 global.check_sync_not_running++;
723 688
724 //pressure_update(); 689 pressure_update();
725 //scheduleUpdateDeviceData(); 690 scheduleUpdateDeviceData();
726 global.lifeData.ascent_rate_meter_per_min = 0; 691 global.lifeData.ascent_rate_meter_per_min = 0;
727 //copyPressureData(); 692 copyPressureData();
728 693
729 if(temperature_carousel > 20.0f) 694 if(temperature_carousel > 20.0f)
730 { 695 {
731 temperature_carousel = 20.0f; 696 temperature_carousel = 20.0f;
732 temperature_changer = -0.1f; 697 temperature_changer = -0.1f;
801 766
802 //Evaluate pressure at 20 ms, 120 ms, 220 ms,... 767 //Evaluate pressure at 20 ms, 120 ms, 220 ms,...
803 if(ticksdiff >= counterPressure100msec * 100 + 20) 768 if(ticksdiff >= counterPressure100msec * 100 + 20)
804 { 769 {
805 global.check_sync_not_running++; 770 global.check_sync_not_running++;
806 // pressure_update(); 771 pressure_update();
807 // scheduleUpdateDeviceData(); 772 scheduleUpdateDeviceData();
808 global.lifeData.ascent_rate_meter_per_min = 0; 773 global.lifeData.ascent_rate_meter_per_min = 0;
809 // copyPressureData(); 774 copyPressureData();
810 counterPressure100msec++; 775 counterPressure100msec++;
811 776
812 if(scheduleCheck_pressure_reached_dive_mode_level()) 777 if(scheduleCheck_pressure_reached_dive_mode_level())
813 global.mode = MODE_DIVE; 778 global.mode = MODE_DIVE;
814 } 779 }
815 780
816 //evaluate compass data at 50 ms, 150 ms, 250 ms,... 781 //evaluate compass data at 50 ms, 150 ms, 250 ms,...
817 782
818 if(ticksdiff >= counterCompass100msec * 100 + 50) 783 if(ticksdiff >= counterCompass100msec * 100 + 50)
819 { 784 {
820 // compass_read(); 785 compass_read();
821 // acceleration_read(); 786 acceleration_read();
822 // compass_calc(); 787 compass_calc();
823 // copyCompassData(); 788 copyCompassData();
824 counterCompass100msec++; 789 counterCompass100msec++;
825 } 790 }
826 791
827 //evaluate compass data at 70 ms, 170 ms, 270 ms,... 792 //evaluate compass data at 70 ms, 170 ms, 270 ms,...
828 if(ticksdiff >= counterAmbientLight100msec * 100 + 70) 793 if(ticksdiff >= counterAmbientLight100msec * 100 + 70)
871 scheduleUpdateLifeData(0); 836 scheduleUpdateLifeData(0);
872 decom_oxygen_calculate_otu_degrade(&global.lifeData.otu, global.seconds_since_last_dive); 837 decom_oxygen_calculate_otu_degrade(&global.lifeData.otu, global.seconds_since_last_dive);
873 decom_oxygen_calculate_cns_degrade(&global.lifeData.cns, global.seconds_since_last_dive); 838 decom_oxygen_calculate_cns_degrade(&global.lifeData.cns, global.seconds_since_last_dive);
874 global.lifeData.desaturation_time_minutes = decom_calc_desaturation_time(global.lifeData.tissue_nitrogen_bar,global.lifeData.tissue_helium_bar,global.lifeData.pressure_surface_bar); 839 global.lifeData.desaturation_time_minutes = decom_calc_desaturation_time(global.lifeData.tissue_nitrogen_bar,global.lifeData.tissue_helium_bar,global.lifeData.pressure_surface_bar);
875 battery_charger_get_status_and_contral_battery_gas_gauge(0); 840 battery_charger_get_status_and_contral_battery_gas_gauge(0);
876 // battery_gas_gauge_get_data(); 841 battery_gas_gauge_get_data();
877 842
878 // copyCnsAndOtuData(); 843 copyCnsAndOtuData();
879 // copyTimeData(); 844 copyTimeData();
880 // copyBatteryData(); 845 copyBatteryData();
881 // copyDeviceData(); 846 copyDeviceData();
882 847
883 // // new hw 170523 848 // new hw 170523
884 // if(global.I2C_SystemStatus != HAL_OK) 849 if(global.I2C_SystemStatus != HAL_OK)
885 // { 850 {
886 // MX_I2C1_TestAndClear(); 851 MX_I2C1_TestAndClear();
887 // MX_I2C1_Init(); 852 MX_I2C1_Init();
888 // if(!is_init_pressure_done()) 853 if(!is_init_pressure_done())
889 // { 854 {
890 // init_pressure(); 855 init_pressure();
891 // } 856 }
892 // } 857 }
893 858
894 counterCompass100msec = 0; 859 counterCompass100msec = 0;
895 counterPressure100msec = 0; 860 counterPressure100msec = 0;
896 counterAmbientLight100msec = 0; 861 counterAmbientLight100msec = 0;
897 counterWireless1msec = 0; 862 counterWireless1msec = 0;
1184 1149
1185 temperature_centigrad_int32 = (int32_t)(get_temperature() * 100); 1150 temperature_centigrad_int32 = (int32_t)(get_temperature() * 100);
1186 if(temperature_centigrad_int32 < global.deviceData.temperatureMinimum.value_int32) 1151 if(temperature_centigrad_int32 < global.deviceData.temperatureMinimum.value_int32)
1187 { 1152 {
1188 global.deviceData.temperatureMinimum.value_int32 = temperature_centigrad_int32; 1153 global.deviceData.temperatureMinimum.value_int32 = temperature_centigrad_int32;
1189 /*Last_change_time?*/ scheduleSetDate(&global.deviceData.temperatureMinimum); 1154 scheduleSetDate(&global.deviceData.temperatureMinimum);
1190 } 1155 }
1191 1156
1192 if(temperature_centigrad_int32 > global.deviceData.temperatureMaximum.value_int32) 1157 if(temperature_centigrad_int32 > global.deviceData.temperatureMaximum.value_int32)
1193 { 1158 {
1194 global.deviceData.temperatureMaximum.value_int32 = temperature_centigrad_int32; 1159 global.deviceData.temperatureMaximum.value_int32 = temperature_centigrad_int32;
1195 /*Last_change_time?*/ scheduleSetDate(&global.deviceData.temperatureMaximum); 1160 scheduleSetDate(&global.deviceData.temperatureMaximum);
1196 } 1161 }
1197 1162
1198 pressure_mbar_int32 = (int32_t)get_pressure_mbar(); 1163 pressure_mbar_int32 = (int32_t)get_pressure_mbar();
1199 if(pressure_mbar_int32 > global.deviceData.depthMaximum.value_int32) 1164 if(pressure_mbar_int32 > global.deviceData.depthMaximum.value_int32)
1200 { 1165 {
1201 global.deviceData.depthMaximum.value_int32 = pressure_mbar_int32; 1166 global.deviceData.depthMaximum.value_int32 = pressure_mbar_int32;
1202 /*Last_change_time?*/ scheduleSetDate(&global.deviceData.depthMaximum); 1167 scheduleSetDate(&global.deviceData.depthMaximum);
1203 } 1168 }
1204 1169
1205 voltage_mvolt_int32 = (int32_t)(get_voltage() * 1000); 1170 voltage_mvolt_int32 = (int32_t)(get_voltage() * 1000);
1206 if(voltage_mvolt_int32 < global.deviceData.voltageMinimum.value_int32) 1171 if(voltage_mvolt_int32 < global.deviceData.voltageMinimum.value_int32)
1207 { 1172 {
1208 global.deviceData.voltageMinimum.value_int32 = voltage_mvolt_int32; 1173 global.deviceData.voltageMinimum.value_int32 = voltage_mvolt_int32;
1209 /*Last_change_time?*/ scheduleSetDate(&global.deviceData.voltageMinimum); 1174 scheduleSetDate(&global.deviceData.voltageMinimum);
1210 } 1175 }
1211 1176
1212 /* third step, counter */ 1177 /* third step, counter */
1213 switch (global.mode) 1178 switch (global.mode)
1214 { 1179 {
1231 1196
1232 1197
1233 void scheduleUpdateDeviceDataChargerFull(void) 1198 void scheduleUpdateDeviceDataChargerFull(void)
1234 { 1199 {
1235 global.deviceData.batteryChargeCompleteCycles.value_int32++; 1200 global.deviceData.batteryChargeCompleteCycles.value_int32++;
1236 /*Last_change_time?*/ scheduleSetDate(&global.deviceData.batteryChargeCompleteCycles); 1201 scheduleSetDate(&global.deviceData.batteryChargeCompleteCycles);
1237 } 1202 }
1238 1203
1239 1204
1240 void scheduleUpdateDeviceDataChargerCharging(void) 1205 void scheduleUpdateDeviceDataChargerCharging(void)
1241 { 1206 {
1242 global.deviceData.batteryChargeCycles.value_int32++; 1207 global.deviceData.batteryChargeCycles.value_int32++;
1243 /*Last_change_time?*/ scheduleSetDate(&global.deviceData.batteryChargeCycles); 1208 scheduleSetDate(&global.deviceData.batteryChargeCycles);
1244 } 1209 }
1245 1210
1246 1211
1247 /** 1212 /**
1248 ****************************************************************************** 1213 ******************************************************************************