comparison Small_CPU/Src/scheduler.c @ 277:580822b5d3d1 IPC_Sync_Improvment_3

Rework SPI error handling. SPI_Start_single_TxRx_with_Master evaluated the incoming data for a condition to send device instead of life data. In case of invalid input data this may cause unintended transmission of device data => now lifedata is send if incoming data is expected to be invalid The SPI timeout monitoring was done at the beginning of the mode loop. A timeout may have been detected even if meanwhile valid data was received (this is evaluated at x20ms) => Moved the timeout monitoring after the handling of incoming data
author ideenmodellierer
date Sun, 28 Apr 2019 10:16:38 +0200
parents a91d99265884
children a09b1855d656
comparison
equal deleted inserted replaced
276:8e9c502c0b06 277:580822b5d3d1
419 global.sync_error_count++; 419 global.sync_error_count++;
420 420
421 /* Try to start communication again. If exchange is stuck during execution for some reason the TX will be aborted by the 421 /* Try to start communication again. If exchange is stuck during execution for some reason the TX will be aborted by the
422 * function error handler 422 * function error handler
423 */ 423 */
424 SPI_Start_single_TxRx_with_Master(); 424 HAL_SPI_TransmitReceive_DMA(&hspi1,(uint8_t*) &(global.dataSendToMaster),(uint8_t*) &(global.dataSendToSlave), EXCHANGE_BUFFERSIZE);
425 Scheduler.communicationTimeout = SPI_COM_TIMEOUT_COMMON; /* Reduce error detection time */ 425 Scheduler.communicationTimeout = SPI_COM_TIMEOUT_COMMON; /* Reduce error detection time */
426 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_HARD); 426 Scheduler_Request_sync_with_SPI(SPI_SYNC_METHOD_HARD);
427 } 427 }
428 } 428 }
429 429
457 global.lifeData.counterSecondsShallowDepth = 0; 457 global.lifeData.counterSecondsShallowDepth = 0;
458 458
459 Scheduler.tickstart = HAL_GetTick(); 459 Scheduler.tickstart = HAL_GetTick();
460 while(global.mode == MODE_DIVE) 460 while(global.mode == MODE_DIVE)
461 { 461 {
462 schedule_check_resync();
463 lasttick = HAL_GetTick(); 462 lasttick = HAL_GetTick();
464 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); 463 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick);
465 464
466 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) 465 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10)
467 { 466 {
468 SPI_Evaluate_RX_Data(); 467 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */
469 Scheduler.counterSPIdata100msec++; 468 {
469 Scheduler.counterSPIdata100msec++;
470 }
471 schedule_check_resync();
470 } 472 }
471 473
472 //Evaluate pressure at 20 ms, 120 ms, 220 ms,.... 474 //Evaluate pressure at 20 ms, 120 ms, 220 ms,....
473 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) 475 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20)
474 { 476 {
475 global.check_sync_not_running++; 477 global.check_sync_not_running++;
476 pressure_update(); 478 pressure_update_alternating();
477 scheduleUpdateDeviceData(); 479 scheduleUpdateDeviceData();
478 #ifdef DEMOMODE 480 #ifdef DEMOMODE
479 if(global.demo_mode) 481 if(global.demo_mode)
480 { 482 {
481 int turbo_seconds = demo_modify_temperature_and_pressure(global.lifeData.dive_time_seconds, Scheduler.counterPressure100msec, global.ceiling_from_main_CPU_mbar); 483 int turbo_seconds = demo_modify_temperature_and_pressure(global.lifeData.dive_time_seconds, Scheduler.counterPressure100msec, global.ceiling_from_main_CPU_mbar);
661 float temperature_carousel = 0.0f; 663 float temperature_carousel = 0.0f;
662 float temperature_changer = 0.1f; 664 float temperature_changer = 0.1f;
663 665
664 while(global.mode == MODE_TEST) 666 while(global.mode == MODE_TEST)
665 { 667 {
666 schedule_check_resync();
667 lasttick = HAL_GetTick(); 668 lasttick = HAL_GetTick();
668 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); 669 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick);
669 670
670 //Evaluate received data at 10 ms, 110 ms, 210 ms,... 671 //Evaluate received data at 10 ms, 110 ms, 210 ms,...
671 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) 672 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10)
672 { 673 {
673 SPI_Evaluate_RX_Data(); 674 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */
674 Scheduler.counterSPIdata100msec++; 675 {
676 Scheduler.counterSPIdata100msec++;
677 }
678 schedule_check_resync();
675 } 679 }
676 680
677 //Evaluate pressure at 20 ms, 120 ms, 220 ms,... 681 //Evaluate pressure at 20 ms, 120 ms, 220 ms,...
678 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) 682 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20)
679 { 683 {
680 global.check_sync_not_running++; 684 global.check_sync_not_running++;
681 685
682 pressure_update(); 686 pressure_update_alternating();
683 scheduleUpdateDeviceData(); 687 scheduleUpdateDeviceData();
684 global.lifeData.ascent_rate_meter_per_min = 0; 688 global.lifeData.ascent_rate_meter_per_min = 0;
685 copyPressureData(); 689 copyPressureData();
686 690
687 if(temperature_carousel > 20.0f) 691 if(temperature_carousel > 20.0f)
735 global.dataSendToMaster.mode = MODE_SURFACE; 739 global.dataSendToMaster.mode = MODE_SURFACE;
736 global.deviceDataSendToMaster.mode = MODE_SURFACE; 740 global.deviceDataSendToMaster.mode = MODE_SURFACE;
737 741
738 while(global.mode == MODE_SURFACE) 742 while(global.mode == MODE_SURFACE)
739 { 743 {
740 schedule_check_resync(); 744
741 lasttick = HAL_GetTick(); 745 lasttick = HAL_GetTick();
742 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); 746 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick);
743 747
744 if(setButtonsNow == 1) 748 if(setButtonsNow == 1)
745 { 749 {
752 { 756 {
753 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */ 757 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */
754 { 758 {
755 Scheduler.counterSPIdata100msec++; 759 Scheduler.counterSPIdata100msec++;
756 } 760 }
761 schedule_check_resync();
757 } 762 }
758 763
759 /* Evaluate pressure at 20 ms, 120 ms, 220 ms,... duration ~22ms] */ 764 /* Evaluate pressure at 20 ms, 120 ms, 220 ms,... duration ~22ms] */
760 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) 765 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20)
761 { 766 {
762 global.check_sync_not_running++; 767 global.check_sync_not_running++;
763 pressure_update(); 768 pressure_update_alternating();
764 scheduleUpdateDeviceData(); 769 scheduleUpdateDeviceData();
765 global.lifeData.ascent_rate_meter_per_min = 0; 770 global.lifeData.ascent_rate_meter_per_min = 0;
766 copyPressureData(); 771 copyPressureData();
767 Scheduler.counterPressure100msec++; 772 Scheduler.counterPressure100msec++;
768 773