Mercurial > public > ostc4
comparison Small_CPU/Src/scheduler.c @ 691:52d68cf9994c Betatest
Improvment external interface usage:
The previous implementation of the external interface was straight forward for ADC and Co2 UART usage. The new implementation provides the possibility to configurate the behavior of the external interface. e.g. Switching of external3,3V and ADC separatly and selection of UART protocol.
author | Ideenmodellierer |
---|---|
date | Fri, 05 Aug 2022 15:26:28 +0200 |
parents | 079bb5b22c06 |
children | f1b40364b0af |
comparison
equal
deleted
inserted
replaced
690:fca2bd25e6e2 | 691:52d68cf9994c |
---|---|
311 if((global.dataSendToSlave.data.externalInterface_Cmd && EXT_INTERFACE_33V_ON) != externalInterface_isEnabledPower33()) | 311 if((global.dataSendToSlave.data.externalInterface_Cmd && EXT_INTERFACE_33V_ON) != externalInterface_isEnabledPower33()) |
312 { | 312 { |
313 externalInterface_SwitchPower33(global.dataSendToSlave.data.externalInterface_Cmd && EXT_INTERFACE_33V_ON); | 313 externalInterface_SwitchPower33(global.dataSendToSlave.data.externalInterface_Cmd && EXT_INTERFACE_33V_ON); |
314 } | 314 } |
315 | 315 |
316 if(global.dataSendToSlave.data.externalInterface_Cmd > EXT_INTERFACE_33V_ON) | 316 if(((global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_ADC_ON) != 0) != externalInterface_isEnabledADC()) |
317 { | |
318 externalInterface_SwitchADC(global.dataSendToSlave.data.externalInterface_Cmd && EXT_INTERFACE_ADC_ON); | |
319 } | |
320 | |
321 | |
322 if(global.dataSendToSlave.data.externalInterface_Cmd & 0x00FF) /* lowest nibble for commands */ | |
317 { | 323 { |
318 externalInterface_ExecuteCmd(global.dataSendToSlave.data.externalInterface_Cmd); | 324 externalInterface_ExecuteCmd(global.dataSendToSlave.data.externalInterface_Cmd); |
319 } | 325 } |
320 | 326 |
321 | 327 |
503 while(global.mode == MODE_DIVE) | 509 while(global.mode == MODE_DIVE) |
504 { | 510 { |
505 lasttick = HAL_GetTick(); | 511 lasttick = HAL_GetTick(); |
506 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); | 512 ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); |
507 | 513 |
514 #ifdef ENABLE_CO2_SUPPORT | |
515 if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_SENTINEL) | |
516 { | |
517 HandleUARTCO2Data(); | |
518 } | |
519 #endif | |
520 #ifdef ENABLE_SENTINEL_MODE | |
521 if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_SENTINEL) | |
522 { | |
523 HandleUARTSentinelData(); | |
524 } | |
525 #endif | |
526 | |
527 | |
508 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) | 528 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) |
509 { | 529 { |
510 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */ | 530 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */ |
511 { | 531 { |
512 Scheduler.counterSPIdata100msec++; | 532 Scheduler.counterSPIdata100msec++; |
513 } | 533 } |
514 schedule_check_resync(); | 534 schedule_check_resync(); |
515 | 535 |
516 extAdcChannel = externalInterface_ReadAndSwitch(); | 536 if(externalInterface_isEnabledADC()) |
517 if(extAdcChannel != EXTERNAL_ADC_NO_DATA) | 537 { |
518 { | 538 extAdcChannel = externalInterface_ReadAndSwitch(); |
519 externalInterface_CalculateADCValue(extAdcChannel); | 539 if(extAdcChannel != EXTERNAL_ADC_NO_DATA) |
520 copyExtADCdata(); | 540 { |
521 } | 541 externalInterface_CalculateADCValue(extAdcChannel); |
542 } | |
543 } | |
544 copyExtADCdata(); | |
522 copyExtCO2data(); | 545 copyExtCO2data(); |
523 } | 546 } |
524 | 547 |
525 //Evaluate pressure at 20 ms, 120 ms, 220 ms,.... | 548 //Evaluate pressure at 20 ms, 120 ms, 220 ms,.... |
526 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) | 549 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) |
804 if(setButtonsNow == 1) | 827 if(setButtonsNow == 1) |
805 { | 828 { |
806 if(scheduleSetButtonResponsiveness()) | 829 if(scheduleSetButtonResponsiveness()) |
807 setButtonsNow = 0; | 830 setButtonsNow = 0; |
808 } | 831 } |
809 | 832 |
810 HandleUARTData(); | 833 #ifdef ENABLE_CO2_SUPPORT |
834 if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_SENTINEL) | |
835 { | |
836 HandleUARTCO2Data(); | |
837 } | |
838 #endif | |
839 #ifdef ENABLE_SENTINEL_MODE | |
840 if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_SENTINEL) | |
841 { | |
842 HandleUARTSentinelData(); | |
843 } | |
844 #endif | |
811 | 845 |
812 /* Evaluate received data at 10 ms, 110 ms, 210 ms,... duration ~<1ms */ | 846 /* Evaluate received data at 10 ms, 110 ms, 210 ms,... duration ~<1ms */ |
813 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) | 847 if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) |
814 { | 848 { |
815 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */ | 849 if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */ |
816 { | 850 { |
817 Scheduler.counterSPIdata100msec++; | 851 Scheduler.counterSPIdata100msec++; |
818 } | 852 } |
819 schedule_check_resync(); | 853 schedule_check_resync(); |
820 extAdcChannel = externalInterface_ReadAndSwitch(); | 854 if(externalInterface_isEnabledADC()) |
821 if(extAdcChannel != EXTERNAL_ADC_NO_DATA) | 855 { |
822 { | 856 extAdcChannel = externalInterface_ReadAndSwitch(); |
823 externalInterface_CalculateADCValue(extAdcChannel); | 857 if(extAdcChannel != EXTERNAL_ADC_NO_DATA) |
824 copyExtADCdata(); | 858 { |
825 } | 859 externalInterface_CalculateADCValue(extAdcChannel); |
860 | |
861 } | |
862 } | |
863 copyExtADCdata(); | |
826 copyExtCO2data(); | 864 copyExtCO2data(); |
827 } | 865 } |
828 | 866 |
829 /* Evaluate pressure at 20 ms, 120 ms, 220 ms,... duration ~22ms] */ | 867 /* Evaluate pressure at 20 ms, 120 ms, 220 ms,... duration ~22ms] */ |
830 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) | 868 if(ticksdiff >= Scheduler.counterPressure100msec * 100 + 20) |
923 | 961 |
924 copyCnsAndOtuData(); | 962 copyCnsAndOtuData(); |
925 copyTimeData(); | 963 copyTimeData(); |
926 copyBatteryData(); | 964 copyBatteryData(); |
927 copyDeviceData(); | 965 copyDeviceData(); |
966 | |
928 | 967 |
929 /* check if I2C is not up an running and try to reactivate if necessary. Also do initialization if problem occured during startup */ | 968 /* check if I2C is not up an running and try to reactivate if necessary. Also do initialization if problem occured during startup */ |
930 if(global.I2C_SystemStatus != HAL_OK) | 969 if(global.I2C_SystemStatus != HAL_OK) |
931 { | 970 { |
932 MX_I2C1_TestAndClear(); | 971 MX_I2C1_TestAndClear(); |
1107 { | 1146 { |
1108 init_pressure(); | 1147 init_pressure(); |
1109 } | 1148 } |
1110 } | 1149 } |
1111 | 1150 |
1112 if(secondsCount >= 30) | 1151 if((secondsCount >= 30) || (global.mode != MODE_SLEEP)) /* Service battery charge state in case sleep is left */ |
1113 { | 1152 { |
1114 pressure_sensor_get_temperature_raw(); | 1153 pressure_sensor_get_temperature_raw(); |
1115 battery_gas_gauge_get_data(); | 1154 battery_gas_gauge_get_data(); |
1116 ReInit_battery_charger_status_pins(); | 1155 ReInit_battery_charger_status_pins(); |
1117 battery_charger_get_status_and_contral_battery_gas_gauge(30); | 1156 battery_charger_get_status_and_contral_battery_gas_gauge(secondsCount); |
1118 // DeInit_battery_charger_status_pins(); | 1157 // DeInit_battery_charger_status_pins(); |
1119 secondsCount = 0; | 1158 secondsCount = 0; |
1120 } | 1159 } |
1121 | 1160 |
1122 pressure_calculation(); | 1161 pressure_calculation(); |
1670 { | 1709 { |
1671 float value; | 1710 float value; |
1672 | 1711 |
1673 uint8_t channel = 0; | 1712 uint8_t channel = 0; |
1674 | 1713 |
1714 uint8_t boolADCBuffer = ~(global.dataSendToMaster.boolADCO2Data & DATA_BUFFER_ADC); | |
1715 | |
1716 boolADCBuffer &= DATA_BUFFER_ADC; | |
1717 global.dataSendToMaster.boolADCO2Data &= ~DATA_BUFFER_ADC; | |
1718 | |
1675 for(channel = 0; channel < MAX_ADC_CHANNEL; channel++) | 1719 for(channel = 0; channel < MAX_ADC_CHANNEL; channel++) |
1676 { | 1720 { |
1677 value = getExternalInterfaceChannel(channel); | 1721 value = getExternalInterfaceChannel(channel); |
1678 global.dataSendToMaster.data[0].extADC_voltage[channel] = value; | 1722 global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].extADC_voltage[channel] = value; |
1679 } | 1723 } |
1724 global.dataSendToMaster.boolADCO2Data |= boolADCBuffer; | |
1680 } | 1725 } |
1681 | 1726 |
1682 void copyExtCO2data() | 1727 void copyExtCO2data() |
1683 { | 1728 { |
1684 uint16_t value; | 1729 uint16_t value; |
1730 uint8_t boolCO2Buffer = ~(global.dataSendToMaster.boolADCO2Data & DATA_BUFFER_CO2); | |
1731 | |
1732 global.dataSendToMaster.boolADCO2Data &= ~DATA_BUFFER_CO2; | |
1733 boolCO2Buffer &= DATA_BUFFER_CO2; | |
1685 | 1734 |
1686 if(externalInterface_GetCO2State()) | 1735 if(externalInterface_GetCO2State()) |
1687 { | 1736 { |
1688 value = externalInterface_GetCO2Value(); | 1737 value = externalInterface_GetCO2Value(); |
1689 global.dataSendToMaster.data[0].CO2_ppm = value; | 1738 global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].CO2_ppm = value; |
1690 value = externalInterface_GetCO2SignalStrength(); | 1739 value = externalInterface_GetCO2SignalStrength(); |
1691 global.dataSendToMaster.data[0].CO2_signalStrength = value; | 1740 global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].CO2_signalStrength = value; |
1692 global.dataSendToMaster.data[0].externalInterface_CmdAnswer = externalInterface_GetCO2State(); | 1741 global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].externalInterface_CmdAnswer = externalInterface_GetCO2State(); |
1693 externalInterface_SetCO2State(EXT_INTERFACE_33V_ON); /* clear command responses */ | 1742 externalInterface_SetCO2State(EXT_INTERFACE_33V_ON); /* clear command responses */ |
1694 } | 1743 } |
1695 else | 1744 else |
1696 { | 1745 { |
1697 global.dataSendToMaster.data[0].CO2_ppm = 0; | 1746 global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].CO2_ppm = 0; |
1698 global.dataSendToMaster.data[0].CO2_signalStrength = 0; | 1747 global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].CO2_signalStrength = 0; |
1699 global.dataSendToMaster.data[0].externalInterface_CmdAnswer = 0; | 1748 global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].externalInterface_CmdAnswer = 0; |
1700 } | 1749 } |
1750 global.dataSendToMaster.boolADCO2Data |= boolCO2Buffer; | |
1701 } | 1751 } |
1702 | 1752 |
1703 typedef enum | 1753 typedef enum |
1704 { | 1754 { |
1705 SPI3_OK = 0x00, | 1755 SPI3_OK = 0x00, |