comparison Small_CPU/Src/scheduler.c @ 662:1b995079c045 Betatest

PSCR Mode
author heinrichs weikamp
date Tue, 14 Dec 2021 15:36:10 +0100
parents 5149cd644fbc
children 079bb5b22c06
comparison
equal deleted inserted replaced
661:87bee7cc77b3 662:1b995079c045
40 #include "calc_crush.h" 40 #include "calc_crush.h"
41 #include "stm32f4xx_hal_rtc_ex.h" 41 #include "stm32f4xx_hal_rtc_ex.h"
42 #include "decom.h" 42 #include "decom.h"
43 #include "tm_stm32f4_otp.h" 43 #include "tm_stm32f4_otp.h"
44 #include "externalInterface.h" 44 #include "externalInterface.h"
45 #include "uart.h"
45 46
46 /* uncomment to enable restoting of last known date in case of a power loss (RTC looses timing data) */ 47 /* uncomment to enable restoting of last known date in case of a power loss (RTC looses timing data) */
47 /* #define RESTORE_LAST_KNOWN_DATE */ 48 /* #define RESTORE_LAST_KNOWN_DATE */
48 49
49 #define INVALID_PREASURE_VALUE (0.0f) 50 #define INVALID_PREASURE_VALUE (0.0f)
88 void copyTissueData(void); 89 void copyTissueData(void);
89 void copyVpmCrushingData(void); 90 void copyVpmCrushingData(void);
90 void copyDeviceData(void); 91 void copyDeviceData(void);
91 void copyPICdata(void); 92 void copyPICdata(void);
92 void copyExtADCdata(); 93 void copyExtADCdata();
94 void copyExtCO2data();
93 static void schedule_update_timer_helper(int8_t thisSeconds); 95 static void schedule_update_timer_helper(int8_t thisSeconds);
94 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow); 96 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow);
95 97
96 void scheduleSetDate(SDeviceLine *line); 98 void scheduleSetDate(SDeviceLine *line);
97 99
299 /* for device data updates */ 301 /* for device data updates */
300 deviceDataFlashValid = 0; 302 deviceDataFlashValid = 0;
301 memcpy(&DeviceDataFlash, &global.dataSendToSlave.data.DeviceData, sizeof(SDevice)); 303 memcpy(&DeviceDataFlash, &global.dataSendToSlave.data.DeviceData, sizeof(SDevice));
302 deviceDataFlashValid = 1; 304 deviceDataFlashValid = 1;
303 305
306
307 /* handle external interface requests */
308
309 if((global.dataSendToSlave.data.externalInterface_Cmd && EXT_INTERFACE_33V_ON) != externalInterface_isEnabledPower33())
310 {
311 externalInterface_SwitchPower33(global.dataSendToSlave.data.externalInterface_Cmd && EXT_INTERFACE_33V_ON);
312 }
313
314 if(global.dataSendToSlave.data.externalInterface_Cmd > EXT_INTERFACE_33V_ON)
315 {
316 externalInterface_ExecuteCmd(global.dataSendToSlave.data.externalInterface_Cmd);
317 }
318
319
304 #if 0 320 #if 0
305 //TODO: Temporary placed here. Duration ~210 ms. 321 //TODO: Temporary placed here. Duration ~210 ms.
306 if (global.I2C_SystemStatus != HAL_OK) { 322 if (global.I2C_SystemStatus != HAL_OK) {
307 MX_I2C1_TestAndClear(); 323 MX_I2C1_TestAndClear();
308 MX_I2C1_Init(); 324 MX_I2C1_Init();
499 if(extAdcChannel != EXTERNAL_ADC_NO_DATA) 515 if(extAdcChannel != EXTERNAL_ADC_NO_DATA)
500 { 516 {
501 externalInterface_CalculateADCValue(extAdcChannel); 517 externalInterface_CalculateADCValue(extAdcChannel);
502 copyExtADCdata(); 518 copyExtADCdata();
503 } 519 }
520 copyExtCO2data();
504 } 521 }
505 522
506 //Evaluate pressure at 20 ms, 120 ms, 220 ms,.... 523 //Evaluate pressure at 20 ms, 120 ms, 220 ms,....
507 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) 524 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20)
508 { 525 {
759 776
760 777
761 778
762 void scheduleSurfaceMode(void) 779 void scheduleSurfaceMode(void)
763 { 780 {
764
765 uint32_t ticksdiff = 0; 781 uint32_t ticksdiff = 0;
766 uint32_t lasttick = 0; 782 uint32_t lasttick = 0;
767 uint8_t extAdcChannel = 0; 783 uint8_t extAdcChannel = 0;
784 uint8_t batteryToggle = 0; /* ADC is operating in automatic 2 second cycles => consider for battery charge function call */
785
768 Scheduler.tickstart = HAL_GetTick(); 786 Scheduler.tickstart = HAL_GetTick();
769 Scheduler.counterSPIdata100msec = 0; 787 Scheduler.counterSPIdata100msec = 0;
770 Scheduler.counterCompass100msec = 0; 788 Scheduler.counterCompass100msec = 0;
771 Scheduler.counterPressure100msec = 0; 789 Scheduler.counterPressure100msec = 0;
772 Scheduler.counterAmbientLight100msec = 0; 790 Scheduler.counterAmbientLight100msec = 0;
785 { 803 {
786 if(scheduleSetButtonResponsiveness()) 804 if(scheduleSetButtonResponsiveness())
787 setButtonsNow = 0; 805 setButtonsNow = 0;
788 } 806 }
789 807
808 HandleUARTData();
809
790 /* Evaluate received data at 10 ms, 110 ms, 210 ms,... duration ~<1ms */ 810 /* Evaluate received data at 10 ms, 110 ms, 210 ms,... duration ~<1ms */
791 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) 811 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10)
792 { 812 {
793 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */ 813 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */
794 { 814 {
799 if(extAdcChannel != EXTERNAL_ADC_NO_DATA) 819 if(extAdcChannel != EXTERNAL_ADC_NO_DATA)
800 { 820 {
801 externalInterface_CalculateADCValue(extAdcChannel); 821 externalInterface_CalculateADCValue(extAdcChannel);
802 copyExtADCdata(); 822 copyExtADCdata();
803 } 823 }
824 copyExtCO2data();
804 } 825 }
805 826
806 /* Evaluate pressure at 20 ms, 120 ms, 220 ms,... duration ~22ms] */ 827 /* Evaluate pressure at 20 ms, 120 ms, 220 ms,... duration ~22ms] */
807 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) 828 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20)
808 { 829 {
884 } 905 }
885 else 906 else
886 { 907 {
887 global.lifeData.desaturation_time_minutes = 0; 908 global.lifeData.desaturation_time_minutes = 0;
888 } 909 }
889 battery_gas_gauge_get_data(); 910
890 battery_charger_get_status_and_contral_battery_gas_gauge(1); 911 if(!batteryToggle)
912 {
913 battery_gas_gauge_get_data();
914 battery_charger_get_status_and_contral_battery_gas_gauge(2);
915 batteryToggle = 1;
916 }
917 else
918 {
919 batteryToggle = 0;
920 }
891 921
892 copyCnsAndOtuData(); 922 copyCnsAndOtuData();
893 copyTimeData(); 923 copyTimeData();
894 copyBatteryData(); 924 copyBatteryData();
895 copyDeviceData(); 925 copyDeviceData();
1054 1084
1055 1085
1056 if(global.mode == MODE_SLEEP) 1086 if(global.mode == MODE_SLEEP)
1057 secondsCount += 2; 1087 secondsCount += 2;
1058 1088
1089 externalInterface_InitPower33();
1059 MX_I2C1_Init(); 1090 MX_I2C1_Init();
1060 pressure_sensor_get_pressure_raw(); 1091 pressure_sensor_get_pressure_raw();
1061 1092
1062 /* check if I2C is not up and running and try to reactivate if necessary. Also do initialization if problem occurred during startup */ 1093 /* check if I2C is not up and running and try to reactivate if necessary. Also do initialization if problem occurred during startup */
1063 if(global.I2C_SystemStatus != HAL_OK) 1094 if(global.I2C_SystemStatus != HAL_OK)
1067 I2C_DeInit(); 1098 I2C_DeInit();
1068 HAL_Delay(100); 1099 HAL_Delay(100);
1069 MX_I2C1_Init(); 1100 MX_I2C1_Init();
1070 HAL_Delay(100); 1101 HAL_Delay(100);
1071 1102
1072
1073 if((global.I2C_SystemStatus == HAL_OK) && (!is_init_pressure_done())) 1103 if((global.I2C_SystemStatus == HAL_OK) && (!is_init_pressure_done()))
1074 { 1104 {
1075 init_pressure(); 1105 init_pressure();
1076 } 1106 }
1077 } 1107 }
1078 1108
1079 if(secondsCount >= 30) 1109 if(secondsCount >= 30)
1080 { 1110 {
1081 pressure_sensor_get_temperature_raw(); 1111 pressure_sensor_get_temperature_raw();
1082 battery_gas_gauge_get_data(); 1112 battery_gas_gauge_get_data();
1083 // ReInit_battery_charger_status_pins(); 1113 ReInit_battery_charger_status_pins();
1084 battery_charger_get_status_and_contral_battery_gas_gauge(30); 1114 battery_charger_get_status_and_contral_battery_gas_gauge(30);
1085 // DeInit_battery_charger_status_pins(); 1115 // DeInit_battery_charger_status_pins();
1086 secondsCount = 0; 1116 secondsCount = 0;
1087 } 1117 }
1088 1118
1361 global.deviceData.hoursOfOperation.value_int32++; 1391 global.deviceData.hoursOfOperation.value_int32++;
1362 scheduleSetDate(&global.deviceData.hoursOfOperation); 1392 scheduleSetDate(&global.deviceData.hoursOfOperation);
1363 } 1393 }
1364 break; 1394 break;
1365 1395
1366 case MODE_SLEEP: 1396 case MODE_SLEEP:
1367 case MODE_SHUTDOWN: 1397 case MODE_SHUTDOWN:
1368 break; 1398 break;
1369 } 1399 }
1370 } 1400 }
1371 1401
1634 value = getExternalInterfaceChannel(channel); 1664 value = getExternalInterfaceChannel(channel);
1635 global.dataSendToMaster.data[0].extADC_voltage[channel] = value; 1665 global.dataSendToMaster.data[0].extADC_voltage[channel] = value;
1636 } 1666 }
1637 } 1667 }
1638 1668
1669 void copyExtCO2data()
1670 {
1671 uint16_t value;
1672
1673 if(externalInterface_GetCO2State())
1674 {
1675 value = externalInterface_GetCO2Value();
1676 global.dataSendToMaster.data[0].CO2_ppm = value;
1677 value = externalInterface_GetCO2SignalStrength();
1678 global.dataSendToMaster.data[0].CO2_signalStrength = value;
1679 global.dataSendToMaster.data[0].externalInterface_CmdAnswer = externalInterface_GetCO2State();
1680 externalInterface_SetCO2State(EXT_INTERFACE_33V_ON); /* clear command responses */
1681 }
1682 else
1683 {
1684 global.dataSendToMaster.data[0].CO2_ppm = 0;
1685 global.dataSendToMaster.data[0].CO2_signalStrength = 0;
1686 global.dataSendToMaster.data[0].externalInterface_CmdAnswer = 0;
1687 }
1688 }
1639 1689
1640 typedef enum 1690 typedef enum
1641 { 1691 {
1642 SPI3_OK = 0x00, 1692 SPI3_OK = 0x00,
1643 SPI3_DEINIT = 0x01, 1693 SPI3_DEINIT = 0x01,