comparison Small_CPU/Src/scheduler.c @ 104:22a1094545f3 kittz

Tested and alive.
author Dmitry Romanov <kitt@bk.ru>
date Mon, 24 Dec 2018 16:15:02 +0300
parents b364c75005bb
children 68181cd61f20
comparison
equal deleted inserted replaced
103:f5d2f02dc73f 104:22a1094545f3
179 } 179 }
180 180
181 181
182 void scheduleSpecial_Evaluate_DataSendToSlave(void) 182 void scheduleSpecial_Evaluate_DataSendToSlave(void)
183 { 183 {
184 //TEMPORARY fix for compass calibration.
185 //TODO: Fix I2C timeout for complete solving problem.
186 if(global.mode==MODE_CALIB){
187 return;
188 }
184 189
185 global.dataSendToSlavePending = 0; 190 global.dataSendToSlavePending = 0;
186 if(!global.dataSendToSlaveIsValid) return; 191 if(!global.dataSendToSlaveIsValid) return;
187 192
188 global.dataSendToMaster.confirmRequest.uw = 0; 193 global.dataSendToMaster.confirmRequest.uw = 0;
241 setButtonsNow = 1; 246 setButtonsNow = 1;
242 } 247 }
243 248
244 if(global.dataSendToSlave.setBatteryGaugeNow) 249 if(global.dataSendToSlave.setBatteryGaugeNow)
245 { 250 {
251 if(global.mode!=MODE_CALIB){
246 global.dataSendToMaster.confirmRequest.ub.batterygauge = 1; 252 global.dataSendToMaster.confirmRequest.ub.batterygauge = 1;
247 battery_gas_gauge_set(global.dataSendToSlave.data.newBatteryGaugePercentageFloat); 253 battery_gas_gauge_set(global.dataSendToSlave.data.newBatteryGaugePercentageFloat);
254 }
248 } 255 }
249 256
250 if((global.mode == MODE_SURFACE) && (global.dataSendToSlave.mode == MODE_SHUTDOWN)) 257 if((global.mode == MODE_SURFACE) && (global.dataSendToSlave.mode == MODE_SHUTDOWN))
251 { 258 {
252 global.mode = MODE_SHUTDOWN; 259 global.mode = MODE_SHUTDOWN;
270 deviceDataFlashValid = 0; 277 deviceDataFlashValid = 0;
271 memcpy(&DeviceDataFlash, &global.dataSendToSlave.data.DeviceData, sizeof(SDevice)); 278 memcpy(&DeviceDataFlash, &global.dataSendToSlave.data.DeviceData, sizeof(SDevice));
272 deviceDataFlashValid = 1; 279 deviceDataFlashValid = 1;
273 280
274 281
275 //TODO: (kittz) split by current mode. 282 //TODO: Temporary placed here. Duration ~210 ms.
276 // new hw 170523 283 if (global.I2C_SystemStatus != HAL_OK) {
277 // if (global.I2C_SystemStatus != HAL_OK) { 284 MX_I2C1_TestAndClear();
278 // MX_I2C1_TestAndClear(); 285 MX_I2C1_Init();
279 // MX_I2C1_Init(); 286 // init_pressure();
280 // if (!is_init_pressure_done()) { 287 // compass_init(0, 7);
281 // init_pressure(); 288 // accelerator_init();
282 // } 289 }
283 // } 290 //Collect and copy sensor data just in one place.
284 291 //TODO: compass_calib_common needs big refactor.
285 292 compass_read();
286 // pressure_update(); 293 acceleration_read();
287 // 294 compass_calc();
288 // compass_read(); 295 pressure_update();
289 // acceleration_read();
290 // compass_calc();
291 //
292 //
293 copyPressureData(); 296 copyPressureData();
294 battery_gas_gauge_get_data(); 297 battery_gas_gauge_get_data();
295 copyCompassData(); 298 copyCompassData();
296 copyCnsAndOtuData(); 299 // copyCnsAndOtuData(); //TODO: move here.
297 copyTimeData(); 300 copyTimeData();
298 copyBatteryData(); 301 // copyBatteryData(); // TODO: move here.
299 copyDeviceData(); 302 copyDeviceData();
300 copyVpmCrushingData(); 303 copyVpmCrushingData();
301 // 304 //
302 scheduleUpdateDeviceData(); 305 scheduleUpdateDeviceData();
303 306
436 * @date 18-June-2015 439 * @date 18-June-2015
437 ****************************************************************************** 440 ******************************************************************************
438 */ 441 */
439 void schedule_check_resync(void) 442 void schedule_check_resync(void)
440 { 443 {
441 //TODO: (kittz) test for stability 444 //TODO: убрать к хуям
442 if((global.check_sync_not_running >= 2)) 445 if((global.check_sync_not_running >= 2))
443 { 446 {
444 // global.dataSendToSlaveIsNotValidCount = 0; 447 // global.dataSendToSlaveIsNotValidCount = 0;
445 // global.check_sync_not_running = 0; 448 // global.check_sync_not_running = 0;
446 // global.sync_error_count++; 449 // global.sync_error_count++;
447 // MX_SPI_DeInit(); 450 // MX_SPI_DeInit();
448 // HAL_Delay(30); /* could be closer to length of data transmission 23.Feb.2015 hw */ 451 // HAL_Delay(30); /* could be closer to length of data transmission 23.Feb.2015 hw */
449 // MX_DMA_Init(); 452 // MX_DMA_Init();
450 // MX_SPI1_Init(); 453 // MX_SPI1_Init();
451 SPI_Start_single_TxRx_with_Master(); 454 // SPI_Start_single_TxRx_with_Master();
452 } 455 }
453 } 456 }
454 457
455 458
456 /** 459 /**
507 510
508 //Evaluate pressure at 20 ms, 120 ms, 220 ms,.... 511 //Evaluate pressure at 20 ms, 120 ms, 220 ms,....
509 if(ticksdiff >= counterPressure100msec * 100 + 20) 512 if(ticksdiff >= counterPressure100msec * 100 + 20)
510 { 513 {
511 global.check_sync_not_running++; 514 global.check_sync_not_running++;
512 pressure_update(); 515 // pressure_update();
513 scheduleUpdateDeviceData(); 516 // scheduleUpdateDeviceData();
514 if(global.demo_mode) 517 if(global.demo_mode)
515 { 518 {
516 turbo_seconds = demo_modify_temperature_and_pressure(global.lifeData.dive_time_seconds, counterPressure100msec, global.ceiling_from_main_CPU_mbar); 519 turbo_seconds = demo_modify_temperature_and_pressure(global.lifeData.dive_time_seconds, counterPressure100msec, global.ceiling_from_main_CPU_mbar);
517 if(turbo_seconds) 520 if(turbo_seconds)
518 { 521 {
539 counterAscentRate = 0; 542 counterAscentRate = 0;
540 543
541 // if(global.demo_mode) 544 // if(global.demo_mode)
542 // global.lifeData.ascent_rate_meter_per_min /= 4; 545 // global.lifeData.ascent_rate_meter_per_min /= 4;
543 } 546 }
544 copyPressureData(); 547 // copyPressureData();
545 counterPressure100msec++; 548 counterPressure100msec++;
546 } 549 }
547 //evaluate compass data at 50 ms, 150 ms, 250 ms,.... 550 //evaluate compass data at 50 ms, 150 ms, 250 ms,....
548 if(ticksdiff >= counterCompass100msec * 100 + 50) 551 // if(ticksdiff >= counterCompass100msec * 100 + 50)
549 { 552 // {
550 compass_read(); 553 // compass_read();
551 acceleration_read(); 554 // acceleration_read();
552 compass_calc(); 555 // compass_calc();
553 copyCompassData(); 556 // copyCompassData();
554 counterCompass100msec++; 557 // counterCompass100msec++;
555 } 558 // }
556 559
557 if(ticksdiff >= counterAmbientLight100msec * 100 + 70) 560 if(ticksdiff >= counterAmbientLight100msec * 100 + 70)
558 { 561 {
559 adc_ambient_light_sensor_get_data(); 562 adc_ambient_light_sensor_get_data();
560 copyAmbientLightData(); 563 copyAmbientLightData();
717 //Evaluate pressure at 20 ms, 120 ms, 220 ms,... 720 //Evaluate pressure at 20 ms, 120 ms, 220 ms,...
718 if(ticksdiff >= counterPressure100msec * 100 + 20) 721 if(ticksdiff >= counterPressure100msec * 100 + 20)
719 { 722 {
720 global.check_sync_not_running++; 723 global.check_sync_not_running++;
721 724
722 pressure_update(); 725 //pressure_update();
723 scheduleUpdateDeviceData(); 726 //scheduleUpdateDeviceData();
724 global.lifeData.ascent_rate_meter_per_min = 0; 727 global.lifeData.ascent_rate_meter_per_min = 0;
725 copyPressureData(); 728 //copyPressureData();
726 729
727 if(temperature_carousel > 20.0f) 730 if(temperature_carousel > 20.0f)
728 { 731 {
729 temperature_carousel = 20.0f; 732 temperature_carousel = 20.0f;
730 temperature_changer = -0.1f; 733 temperature_changer = -0.1f;
799 802
800 //Evaluate pressure at 20 ms, 120 ms, 220 ms,... 803 //Evaluate pressure at 20 ms, 120 ms, 220 ms,...
801 if(ticksdiff >= counterPressure100msec * 100 + 20) 804 if(ticksdiff >= counterPressure100msec * 100 + 20)
802 { 805 {
803 global.check_sync_not_running++; 806 global.check_sync_not_running++;
804 pressure_update(); 807 // pressure_update();
805 scheduleUpdateDeviceData(); 808 // scheduleUpdateDeviceData();
806 global.lifeData.ascent_rate_meter_per_min = 0; 809 global.lifeData.ascent_rate_meter_per_min = 0;
807 copyPressureData(); 810 // copyPressureData();
808 counterPressure100msec++; 811 counterPressure100msec++;
809 812
810 if(scheduleCheck_pressure_reached_dive_mode_level()) 813 if(scheduleCheck_pressure_reached_dive_mode_level())
811 global.mode = MODE_DIVE; 814 global.mode = MODE_DIVE;
812 } 815 }
813 816
814 //evaluate compass data at 50 ms, 150 ms, 250 ms,... 817 //evaluate compass data at 50 ms, 150 ms, 250 ms,...
815 818
816 if(ticksdiff >= counterCompass100msec * 100 + 50) 819 // if(ticksdiff >= counterCompass100msec * 100 + 50)
817 { 820 // {
818 compass_read(); 821 //// compass_read();
819 acceleration_read(); 822 //// acceleration_read();
820 compass_calc(); 823 // compass_calc();
821 copyCompassData(); 824 // copyCompassData();
822 counterCompass100msec++; 825 // counterCompass100msec++;
823 } 826 // }
824 827
825 //evaluate compass data at 70 ms, 170 ms, 270 ms,... 828 //evaluate compass data at 70 ms, 170 ms, 270 ms,...
826 if(ticksdiff >= counterAmbientLight100msec * 100 + 70) 829 if(ticksdiff >= counterAmbientLight100msec * 100 + 70)
827 { 830 {
828 adc_ambient_light_sensor_get_data(); 831 adc_ambient_light_sensor_get_data();