Mercurial > public > ostc4
comparison Small_CPU/Src/scheduler.c @ 220:e524a824d8f2 Improve_IPC_Sync
Added schedule point for functions executed once in a second
SPI communication takes place every 100ms triggered by the master (main). Synchronisation is done using the SPI RX complete callback which is called ~4ms after communication was started. In the previous implementation this could happen in parallel to usage of data. To solve this potential problem the execution of functions called once a second was moved from 1000ms to 980ms giving a 20ms window for execution.
author | ideenmodellierer |
---|---|
date | Sun, 31 Mar 2019 15:49:47 +0200 |
parents | b95741467355 |
children | 3973208c4a20 |
comparison
equal
deleted
inserted
replaced
219:f9b17e898a7a | 220:e524a824d8f2 |
---|---|
456 */ | 456 */ |
457 void scheduleDiveMode(void) | 457 void scheduleDiveMode(void) |
458 { | 458 { |
459 uint32_t ticksdiff = 0; | 459 uint32_t ticksdiff = 0; |
460 uint32_t lasttick = 0; | 460 uint32_t lasttick = 0; |
461 | |
462 uint8_t counterAscentRate = 0; | 461 uint8_t counterAscentRate = 0; |
463 float lastPressure_bar = 0.0f; | 462 float lastPressure_bar = 0.0f; |
464 global.dataSendToMaster.mode = MODE_DIVE; | 463 global.dataSendToMaster.mode = MODE_DIVE; |
465 global.deviceDataSendToMaster.mode = MODE_DIVE; | 464 global.deviceDataSendToMaster.mode = MODE_DIVE; |
466 //uint16_t counterSecondsShallowDepth = 0; | 465 //uint16_t counterSecondsShallowDepth = 0; |
469 Scheduler.tickstart = HAL_GetTick() - 1000; | 468 Scheduler.tickstart = HAL_GetTick() - 1000; |
470 Scheduler.counterSPIdata100msec = 0; | 469 Scheduler.counterSPIdata100msec = 0; |
471 Scheduler.counterCompass100msec = 0; | 470 Scheduler.counterCompass100msec = 0; |
472 Scheduler.counterPressure100msec = 0; | 471 Scheduler.counterPressure100msec = 0; |
473 Scheduler.counterAmbientLight100msec = 0; | 472 Scheduler.counterAmbientLight100msec = 0; |
473 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; | |
474 | 474 |
475 global.deviceData.diveCycles.value_int32++; | 475 global.deviceData.diveCycles.value_int32++; |
476 scheduleSetDate(&global.deviceData.diveCycles); | 476 scheduleSetDate(&global.deviceData.diveCycles); |
477 global.lifeData.counterSecondsShallowDepth = 0; | 477 global.lifeData.counterSecondsShallowDepth = 0; |
478 | 478 |
540 adc_ambient_light_sensor_get_data(); | 540 adc_ambient_light_sensor_get_data(); |
541 copyAmbientLightData(); | 541 copyAmbientLightData(); |
542 Scheduler.counterAmbientLight100msec++; | 542 Scheduler.counterAmbientLight100msec++; |
543 } | 543 } |
544 | 544 |
545 //Evaluate tissues, toxic data, vpm, etc. once a second | 545 //Evaluate tissues, toxic data, vpm, etc. once a second |
546 if(ticksdiff >= 1000) | 546 if(ticksdiff >= Scheduler.tick_execute1second) |
547 { | 547 { |
548 /* reset counter */ | 548 Scheduler.tick_execute1second = 0xFFFFFFFF; /* execute once only in the second cycle */ |
549 Scheduler.tickstart = HAL_GetTick(); | |
550 | |
551 if(global.dataSendToSlave.diveModeInfo != DIVEMODE_Apnea) | 549 if(global.dataSendToSlave.diveModeInfo != DIVEMODE_Apnea) |
552 { | 550 { |
553 scheduleUpdateLifeData(0); // includes tissues | 551 scheduleUpdateLifeData(0); // includes tissues |
554 global.lifeData.dive_time_seconds++; // there is dive_time_seconds_without_surface_time too | 552 global.lifeData.dive_time_seconds++; // there is dive_time_seconds_without_surface_time too |
555 global.lifeData.ppO2 = decom_calc_ppO2(global.lifeData.pressure_ambient_bar, &global.lifeData.actualGas); | 553 global.lifeData.ppO2 = decom_calc_ppO2(global.lifeData.pressure_ambient_bar, &global.lifeData.actualGas); |
640 if(!is_init_pressure_done()) | 638 if(!is_init_pressure_done()) |
641 { | 639 { |
642 init_pressure(); | 640 init_pressure(); |
643 } | 641 } |
644 } | 642 } |
643 } | |
644 if(ticksdiff >= 1000) | |
645 { | |
646 /* reset counter */ | |
647 Scheduler.tickstart = HAL_GetTick(); | |
645 Scheduler.counterSPIdata100msec = 0; | 648 Scheduler.counterSPIdata100msec = 0; |
646 Scheduler.counterCompass100msec = 0; | 649 Scheduler.counterCompass100msec = 0; |
647 Scheduler.counterPressure100msec = 0; | 650 Scheduler.counterPressure100msec = 0; |
648 Scheduler.counterAmbientLight100msec = 0; | 651 Scheduler.counterAmbientLight100msec = 0; |
652 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; | |
649 } | 653 } |
650 } | 654 } |
651 } | 655 } |
652 | 656 |
653 | 657 |
733 }; | 737 }; |
734 } | 738 } |
735 | 739 |
736 | 740 |
737 | 741 |
738 | |
739 void scheduleSurfaceMode(void) | 742 void scheduleSurfaceMode(void) |
740 { | 743 { |
741 | 744 |
742 uint32_t ticksdiff = 0; | 745 uint32_t ticksdiff = 0; |
743 uint32_t lasttick = 0; | 746 uint32_t lasttick = 0; |
744 Scheduler.tickstart = HAL_GetTick(); | 747 Scheduler.tickstart = HAL_GetTick(); |
745 Scheduler.counterSPIdata100msec = 0; | 748 Scheduler.counterSPIdata100msec = 0; |
746 Scheduler.counterCompass100msec = 0; | 749 Scheduler.counterCompass100msec = 0; |
747 Scheduler.counterPressure100msec = 0; | 750 Scheduler.counterPressure100msec = 0; |
748 Scheduler.counterAmbientLight100msec = 0; | 751 Scheduler.counterAmbientLight100msec = 0; |
752 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; | |
749 | 753 |
750 global.dataSendToMaster.mode = MODE_SURFACE; | 754 global.dataSendToMaster.mode = MODE_SURFACE; |
751 global.deviceDataSendToMaster.mode = MODE_SURFACE; | 755 global.deviceDataSendToMaster.mode = MODE_SURFACE; |
752 | 756 |
753 while(global.mode == MODE_SURFACE) | 757 while(global.mode == MODE_SURFACE) |
760 { | 764 { |
761 if(scheduleSetButtonResponsiveness()) | 765 if(scheduleSetButtonResponsiveness()) |
762 setButtonsNow = 0; | 766 setButtonsNow = 0; |
763 } | 767 } |
764 | 768 |
765 //Evaluate received data at 10 ms, 110 ms, 210 ms,... | 769 /* Evaluate received data at 10 ms, 110 ms, 210 ms,... duration ~<1ms */ |
766 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) | 770 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) |
767 { | 771 { |
768 SPI_Evaluate_RX_Data(); | 772 SPI_Evaluate_RX_Data(); |
769 Scheduler.counterSPIdata100msec++; | 773 Scheduler.counterSPIdata100msec++; |
770 } | 774 } |
771 | 775 |
772 //Evaluate pressure at 20 ms, 120 ms, 220 ms,... | 776 /* Evaluate pressure at 20 ms, 120 ms, 220 ms,... duration ~22ms] */ |
773 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) | 777 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) |
774 { | 778 { |
775 global.check_sync_not_running++; | 779 global.check_sync_not_running++; |
776 pressure_update(); | 780 pressure_update(); |
777 scheduleUpdateDeviceData(); | 781 scheduleUpdateDeviceData(); |
781 | 785 |
782 if(scheduleCheck_pressure_reached_dive_mode_level()) | 786 if(scheduleCheck_pressure_reached_dive_mode_level()) |
783 global.mode = MODE_DIVE; | 787 global.mode = MODE_DIVE; |
784 } | 788 } |
785 | 789 |
786 //Evaluate compass data at 50 ms, 150 ms, 250 ms,... | 790 /* Evaluate compass data at 50 ms, 150 ms, 250 ms,... duration ~5ms */ |
787 if(ticksdiff >= Scheduler.counterCompass100msec * 100 + 50) | 791 if(ticksdiff >= Scheduler.counterCompass100msec * 100 + 50) |
788 { | 792 { |
789 compass_read(); | 793 compass_read(); |
790 acceleration_read(); | 794 acceleration_read(); |
791 compass_calc(); | 795 compass_calc(); |
792 copyCompassData(); | 796 copyCompassData(); |
793 Scheduler.counterCompass100msec++; | 797 Scheduler.counterCompass100msec++; |
794 } | 798 } |
795 | 799 |
796 //evaluate compass data at 70 ms, 170 ms, 270 ms,... | 800 /* evaluate compass data at 70 ms, 170 ms, 270 ms,... duration <1ms */ |
797 if(ticksdiff >= Scheduler.counterAmbientLight100msec * 100 + 70) | 801 if(ticksdiff >= Scheduler.counterAmbientLight100msec * 100 + 70) |
798 { | 802 { |
799 adc_ambient_light_sensor_get_data(); | 803 adc_ambient_light_sensor_get_data(); |
800 copyAmbientLightData(); | 804 copyAmbientLightData(); |
801 Scheduler.counterAmbientLight100msec++; | 805 Scheduler.counterAmbientLight100msec++; |
802 } | 806 } |
803 //Evaluate tissues, toxic data, etc. once a second | 807 |
804 if(ticksdiff >= 1000) | 808 |
805 { | 809 |
806 //Set back tick counter | 810 /* Evaluate tissues, toxic data, etc. once a second... duration ~1ms */ |
807 Scheduler.tickstart = HAL_GetTick(); | 811 if(ticksdiff >= Scheduler.tick_execute1second) |
808 | 812 { |
813 Scheduler.tick_execute1second = 0xFFFFFFFF; | |
809 if(clearDecoNow) | 814 if(clearDecoNow) |
810 { | 815 { |
811 decom_reset_with_1000mbar(&global.lifeData); ///< this should almost reset desaturation time | 816 decom_reset_with_1000mbar(&global.lifeData); ///< this should almost reset desaturation time |
812 // new 160215 hw | 817 // new 160215 hw |
813 global.repetitive_dive = 0; | 818 global.repetitive_dive = 0; |
865 if(!is_init_pressure_done()) | 870 if(!is_init_pressure_done()) |
866 { | 871 { |
867 init_pressure(); | 872 init_pressure(); |
868 } | 873 } |
869 } | 874 } |
875 } | |
876 | |
877 if(ticksdiff >= 1000) | |
878 { | |
879 //Set back tick counter | |
880 Scheduler.tickstart = HAL_GetTick(); | |
870 Scheduler.counterSPIdata100msec = 0; | 881 Scheduler.counterSPIdata100msec = 0; |
871 Scheduler.counterCompass100msec = 0; | 882 Scheduler.counterCompass100msec = 0; |
872 Scheduler.counterPressure100msec = 0; | 883 Scheduler.counterPressure100msec = 0; |
873 Scheduler.counterAmbientLight100msec = 0; | 884 Scheduler.counterAmbientLight100msec = 0; |
885 Scheduler.tick_execute1second = SCHEDULER_TICK_EXE1SEC; | |
874 } | 886 } |
875 } | 887 } |
876 } | 888 } |
877 | 889 |
878 inline void Scheduler_Request_sync_with_SPI(uint8_t SyncMethod) | 890 inline void Scheduler_Request_sync_with_SPI(uint8_t SyncMethod) |