Mercurial > public > ostc4
comparison Small_CPU/Src/scheduler.c @ 89:ff7775cc34c4 kittz
temp! full cyclic SPI
author | Dmitry Romanov <kitt@bk.ru> |
---|---|
date | Fri, 23 Nov 2018 16:52:21 +0300 |
parents | 3db7389d49cc |
children | 83857eb3b12b |
comparison
equal
deleted
inserted
replaced
88:3db7389d49cc | 89:ff7775cc34c4 |
---|---|
179 } | 179 } |
180 | 180 |
181 | 181 |
182 void scheduleSpecial_Evaluate_DataSendToSlave(void) | 182 void scheduleSpecial_Evaluate_DataSendToSlave(void) |
183 { | 183 { |
184 schedule_check_resync(); | |
184 global.dataSendToSlavePending = 0; | 185 global.dataSendToSlavePending = 0; |
185 if(!global.dataSendToSlaveIsValid) return; | 186 if(!global.dataSendToSlaveIsValid) return; |
186 | 187 |
187 global.dataSendToMaster.confirmRequest.uw = 0; | 188 global.dataSendToMaster.confirmRequest.uw = 0; |
188 | 189 |
267 | 268 |
268 /* for device data updates */ | 269 /* for device data updates */ |
269 deviceDataFlashValid = 0; | 270 deviceDataFlashValid = 0; |
270 memcpy(&DeviceDataFlash, &global.dataSendToSlave.data.DeviceData, sizeof(SDevice)); | 271 memcpy(&DeviceDataFlash, &global.dataSendToSlave.data.DeviceData, sizeof(SDevice)); |
271 deviceDataFlashValid = 1; | 272 deviceDataFlashValid = 1; |
273 | |
274 | |
275 //TODO: (kittz) split by current mode. | |
276 // new hw 170523 | |
277 // if (global.I2C_SystemStatus != HAL_OK) { | |
278 // MX_I2C1_TestAndClear(); | |
279 // MX_I2C1_Init(); | |
280 // if (!is_init_pressure_done()) { | |
281 // init_pressure(); | |
282 // } | |
283 // } | |
284 | |
285 | |
286 // pressure_update(); | |
287 | |
288 // compass_read(); | |
289 // acceleration_read(); | |
290 // compass_calc(); | |
291 | |
292 | |
293 // copyPressureData(); | |
294 // battery_gas_gauge_get_data(); | |
295 // if(global.mode==MODE_CALIB)copyCompassData(); | |
296 // copyCnsAndOtuData(); | |
297 // copyTimeData(); | |
298 // copyBatteryData(); | |
299 // copyDeviceData(); | |
300 // copyVpmCrushingData(); | |
301 // deviceDataFlashValid = 1; | |
302 // scheduleUpdateDeviceData(); | |
303 | |
304 | |
272 } | 305 } |
273 | 306 |
274 | 307 |
275 /** | 308 /** |
276 ****************************************************************************** | 309 ****************************************************************************** |
404 ****************************************************************************** | 437 ****************************************************************************** |
405 */ | 438 */ |
406 void schedule_check_resync(void) | 439 void schedule_check_resync(void) |
407 { | 440 { |
408 //TODO: (kittz) test for stability | 441 //TODO: (kittz) test for stability |
409 if((global.check_sync_not_running >= 10)) | 442 if((global.check_sync_not_running >= 2)) |
410 { | 443 { |
411 global.dataSendToSlaveIsNotValidCount = 0; | 444 // global.dataSendToSlaveIsNotValidCount = 0; |
412 global.check_sync_not_running = 0; | 445 // global.check_sync_not_running = 0; |
413 global.sync_error_count++; | 446 // global.sync_error_count++; |
414 MX_SPI_DeInit(); | 447 // MX_SPI_DeInit(); |
415 HAL_Delay(30); /* could be closer to length of data transmission 23.Feb.2015 hw */ | 448 // HAL_Delay(30); /* could be closer to length of data transmission 23.Feb.2015 hw */ |
416 MX_DMA_Init(); | 449 // MX_DMA_Init(); |
417 MX_SPI1_Init(); | 450 // MX_SPI1_Init(); |
418 SPI_Start_single_TxRx_with_Master(); | 451 SPI_Start_single_TxRx_with_Master(); |
419 } | 452 } |
420 } | 453 } |
421 | 454 |
422 | 455 |
741 global.deviceDataSendToMaster.mode = MODE_SURFACE; | 774 global.deviceDataSendToMaster.mode = MODE_SURFACE; |
742 | 775 |
743 while(global.mode == MODE_SURFACE) | 776 while(global.mode == MODE_SURFACE) |
744 { | 777 { |
745 printf("surface...\n"); | 778 printf("surface...\n"); |
746 | 779 // SPI_Start_single_TxRx_with_Master(); |
747 schedule_check_resync(); | 780 schedule_check_resync(); |
748 lasttick = HAL_GetTick(); | 781 lasttick = HAL_GetTick(); |
749 ticksdiff = time_elapsed_ms(tickstart,lasttick); | 782 ticksdiff = time_elapsed_ms(tickstart,lasttick); |
750 | 783 |
751 if(ticksdiff > counterWireless1msec) | 784 if(ticksdiff > counterWireless1msec) |
771 pressure_update(); | 804 pressure_update(); |
772 scheduleUpdateDeviceData(); | 805 scheduleUpdateDeviceData(); |
773 global.lifeData.ascent_rate_meter_per_min = 0; | 806 global.lifeData.ascent_rate_meter_per_min = 0; |
774 copyPressureData(); | 807 copyPressureData(); |
775 counterPressure100msec++; | 808 counterPressure100msec++; |
776 | 809 |
777 if(scheduleCheck_pressure_reached_dive_mode_level()) | 810 if(scheduleCheck_pressure_reached_dive_mode_level()) |
778 global.mode = MODE_DIVE; | 811 global.mode = MODE_DIVE; |
779 } | 812 } |
780 | 813 |
781 //evaluate compass data at 50 ms, 150 ms, 250 ms,... | 814 //evaluate compass data at 50 ms, 150 ms, 250 ms,... |
794 { | 827 { |
795 adc_ambient_light_sensor_get_data(); | 828 adc_ambient_light_sensor_get_data(); |
796 copyAmbientLightData(); | 829 copyAmbientLightData(); |
797 counterAmbientLight100msec++; | 830 counterAmbientLight100msec++; |
798 } | 831 } |
799 //Evaluate tissues, toxic data, etc. once a second | 832 //Evaluate tissues, toxic data, etc. once a second |
800 if(ticksdiff >= 1000) | 833 if(ticksdiff >= 1000) |
801 { | 834 { |
802 if(clearDecoNow) | 835 if(clearDecoNow) |
803 { | 836 { |
804 decom_reset_with_1000mbar(&global.lifeData); ///< this should almost reset desaturation time | 837 decom_reset_with_1000mbar(&global.lifeData); ///< this should almost reset desaturation time |
809 global.accidentFlag = 0; | 842 global.accidentFlag = 0; |
810 global.accidentRemainingSeconds = 0; | 843 global.accidentRemainingSeconds = 0; |
811 vpm_init(&global.vpm, global.conservatism, global.repetitive_dive, global.seconds_since_last_dive); | 844 vpm_init(&global.vpm, global.conservatism, global.repetitive_dive, global.seconds_since_last_dive); |
812 clearDecoNow = 0; | 845 clearDecoNow = 0; |
813 } | 846 } |
814 | 847 |
815 //Set back tick counter | 848 //Set back tick counter |
816 tickstart = HAL_GetTick(); | 849 tickstart = HAL_GetTick(); |
817 | 850 |
818 | 851 |
819 if(global.seconds_since_last_dive) | 852 if(global.seconds_since_last_dive) |
820 { | 853 { |
821 schedule_update_timer_helper(-1); | 854 schedule_update_timer_helper(-1); |
822 // global.seconds_since_last_dive++; | 855 // global.seconds_since_last_dive++; |
823 // if(global.seconds_since_last_dive > 777900) // a bit more than nine days [seconds] | 856 // if(global.seconds_since_last_dive > 777900) // a bit more than nine days [seconds] |
824 // global.seconds_since_last_dive = 0; | 857 // global.seconds_since_last_dive = 0; |
825 } | 858 } |
826 | 859 |
827 if(global.accidentRemainingSeconds) | 860 if(global.accidentRemainingSeconds) |
828 { | 861 { |
829 global.accidentRemainingSeconds--; | 862 global.accidentRemainingSeconds--; |
830 if(!global.accidentRemainingSeconds) | 863 if(!global.accidentRemainingSeconds) |
831 global.accidentFlag = 0; | 864 global.accidentFlag = 0; |
832 } | 865 } |
833 global.dataSendToMaster.accidentFlags = global.accidentFlag; | 866 global.dataSendToMaster.accidentFlags = global.accidentFlag; |
834 | 867 |
835 update_surface_pressure(1); | 868 update_surface_pressure(1); |
836 scheduleUpdateLifeData(0); | 869 scheduleUpdateLifeData(0); |
837 decom_oxygen_calculate_otu_degrade(&global.lifeData.otu, global.seconds_since_last_dive); | 870 decom_oxygen_calculate_otu_degrade(&global.lifeData.otu, global.seconds_since_last_dive); |
838 decom_oxygen_calculate_cns_degrade(&global.lifeData.cns, global.seconds_since_last_dive); | 871 decom_oxygen_calculate_cns_degrade(&global.lifeData.cns, global.seconds_since_last_dive); |
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); | 872 global.lifeData.desaturation_time_minutes = decom_calc_desaturation_time(global.lifeData.tissue_nitrogen_bar,global.lifeData.tissue_helium_bar,global.lifeData.pressure_surface_bar); |
840 battery_charger_get_status_and_contral_battery_gas_gauge(0); | 873 battery_charger_get_status_and_contral_battery_gas_gauge(0); |
841 battery_gas_gauge_get_data(); | 874 battery_gas_gauge_get_data(); |
842 | 875 |
843 copyCnsAndOtuData(); | 876 copyCnsAndOtuData(); |
844 copyTimeData(); | 877 copyTimeData(); |
845 copyBatteryData(); | 878 copyBatteryData(); |
846 copyDeviceData(); | 879 copyDeviceData(); |
847 | 880 |
853 if(!is_init_pressure_done()) | 886 if(!is_init_pressure_done()) |
854 { | 887 { |
855 init_pressure(); | 888 init_pressure(); |
856 } | 889 } |
857 } | 890 } |
858 | 891 |
859 counterCompass100msec = 0; | 892 counterCompass100msec = 0; |
860 counterPressure100msec = 0; | 893 counterPressure100msec = 0; |
861 counterAmbientLight100msec = 0; | 894 counterAmbientLight100msec = 0; |
862 counterWireless1msec = 0; | 895 counterWireless1msec = 0; |
863 } | 896 } |