Mercurial > public > ostc4
comparison Small_CPU/Src/externalInterface.c @ 916:4832981f9af8 Evo_2_23
External sensor UART: Switch to DMA TX transfers:
The previous version used polling tx function to transfer data. Because of the short command length of the protocols supported this was no big issue. New protocolls (like GNSS) have longer command sequence which have an impact to the program flow. That's why the implementation has been changed to DMA transmission.
author | Ideenmodellierer |
---|---|
date | Mon, 28 Oct 2024 20:34:58 +0100 |
parents | ad96f99ebc78 |
children | f72613a152dd |
comparison
equal
deleted
inserted
replaced
915:ff318ae65dd0 | 916:4832981f9af8 |
---|---|
33 #include "data_exchange.h" | 33 #include "data_exchange.h" |
34 #include "pressure.h" | 34 #include "pressure.h" |
35 #include "uartProtocol_O2.h" | 35 #include "uartProtocol_O2.h" |
36 #include "uartProtocol_Co2.h" | 36 #include "uartProtocol_Co2.h" |
37 #include "uartProtocol_Sentinel.h" | 37 #include "uartProtocol_Sentinel.h" |
38 #include "uartProtocol_GNSS.h" | |
38 | 39 |
39 extern SGlobal global; | 40 extern SGlobal global; |
40 extern UART_HandleTypeDef huart1; | 41 extern UART_HandleTypeDef huart1; |
41 | 42 |
42 #define ADC_ANSWER_LENGTH (5u) /* 3424 will provide addr + 4 data bytes */ | 43 #define ADC_ANSWER_LENGTH (5u) /* 3424 will provide addr + 4 data bytes */ |
90 static uint8_t externalInterface_SensorState[EXT_INTERFACE_SENSOR_CNT]; | 91 static uint8_t externalInterface_SensorState[EXT_INTERFACE_SENSOR_CNT]; |
91 | 92 |
92 static float LookupCO2PressureCorrection[LOOKUP_CO2_CORR_TABLE_MAX / LOOKUP_CO2_CORR_TABLE_SCALE]; /* lookup table for pressure compensation values */ | 93 static float LookupCO2PressureCorrection[LOOKUP_CO2_CORR_TABLE_MAX / LOOKUP_CO2_CORR_TABLE_SCALE]; /* lookup table for pressure compensation values */ |
93 | 94 |
94 static uint16_t externalInterfaceMuxReqIntervall = 0xffff; /* delay between switching from one MUX channel to the next */ | 95 static uint16_t externalInterfaceMuxReqIntervall = 0xffff; /* delay between switching from one MUX channel to the next */ |
95 static uint8_t activeUartChannel = 0; /* Index of the sensor port which is selected by the mux or 0 if no mux is connected */ | 96 static uint8_t activeUartChannel = 0xff; |
96 | 97 |
97 | 98 |
98 static void externalInface_MapUartToLegacyADC(uint8_t* pMap); | 99 static void externalInface_MapUartToLegacyADC(uint8_t* pMap); |
99 static void externalInterface_CheckBaudrate(uint8_t sensorType); | 100 static void externalInterface_CheckBaudrate(uint8_t sensorType); |
100 | 101 |
385 || ((protocol == EXT_INTERFACE_UART_O2) && (externalAutoDetect >= DETECTION_UARTMUX) && (externalAutoDetect <= DETECTION_DIGO2_3)) | 386 || ((protocol == EXT_INTERFACE_UART_O2) && (externalAutoDetect >= DETECTION_UARTMUX) && (externalAutoDetect <= DETECTION_DIGO2_3)) |
386 | 387 |
387 #ifdef ENABLE_CO2_SUPPORT | 388 #ifdef ENABLE_CO2_SUPPORT |
388 || ((externalAutoDetect >= DETECTION_CO2_0) && (externalAutoDetect <= DETECTION_CO2_3)) | 389 || ((externalAutoDetect >= DETECTION_CO2_0) && (externalAutoDetect <= DETECTION_CO2_3)) |
389 #endif | 390 #endif |
391 #ifdef ENABLE_GNSS_SUPPORT | |
392 || ((externalAutoDetect >= DETECTION_GNSS_0) && (externalAutoDetect <= DETECTION_GNSS_3)) | |
393 #endif | |
394 | |
390 #ifdef ENABLE_SENTINEL_MODE | 395 #ifdef ENABLE_SENTINEL_MODE |
391 || ((protocol == EXT_INTERFACE_UART_SENTINEL) && (externalAutoDetect == DETECTION_SENTINEL)) | 396 || ((protocol == EXT_INTERFACE_UART_SENTINEL) && (externalAutoDetect == DETECTION_SENTINEL)) |
392 #endif | 397 #endif |
393 ) | 398 ) |
394 { | 399 { |
606 break; | 611 break; |
607 } | 612 } |
608 } | 613 } |
609 } | 614 } |
610 } | 615 } |
616 for(index = 0; index < EXT_INTERFACE_SENSOR_CNT-1; index++) | |
617 { | |
618 if(pMap[index] == SENSOR_GNSS) | |
619 { | |
620 for(index2 = 0; index2 < MAX_ADC_CHANNEL; index2++) | |
621 { | |
622 if(pMap[index2] == SENSOR_NONE) | |
623 { | |
624 pMap[index2] = SENSOR_GNSSM; /* store a mirror instance needed for visualization */ | |
625 Mux2ADCMap[index2] = index; | |
626 break; | |
627 } | |
628 } | |
629 } | |
630 } | |
611 #ifdef ENABLE_SENTINEL_MODE | 631 #ifdef ENABLE_SENTINEL_MODE |
612 if(pMap[EXT_INTERFACE_MUX_OFFSET] == SENSOR_SENTINEL) | 632 if(pMap[EXT_INTERFACE_MUX_OFFSET] == SENSOR_SENTINEL) |
613 { | 633 { |
614 for(index2 = 0; index2 < MAX_ADC_CHANNEL; index2++) | 634 for(index2 = 0; index2 < MAX_ADC_CHANNEL; index2++) |
615 { | 635 { |
638 void externalInterface_AutodetectSensor() | 658 void externalInterface_AutodetectSensor() |
639 { | 659 { |
640 static uint8_t sensorIndex = 0; | 660 static uint8_t sensorIndex = 0; |
641 static uint8_t uartMuxChannel = 0; | 661 static uint8_t uartMuxChannel = 0; |
642 uint8_t index = 0; | 662 uint8_t index = 0; |
663 #ifdef ENABLE_GNSS_SUPPORT | |
664 uint8_t detectionDelayCnt = 0; | |
665 #endif | |
643 uint8_t cntSensor = 0; | 666 uint8_t cntSensor = 0; |
644 uint8_t cntUARTSensor = 0; | 667 uint8_t cntUARTSensor = 0; |
645 #ifdef ENABLE_CO2_SUPPORT | 668 #ifdef ENABLE_CO2_SUPPORT |
646 uint8_t cmdString[10]; | 669 uint8_t cmdString[10]; |
647 uint8_t cmdLength = 0; | 670 uint8_t cmdLength = 0; |
704 } | 727 } |
705 } | 728 } |
706 externalInterfaceMuxReqIntervall = 1100; | 729 externalInterfaceMuxReqIntervall = 1100; |
707 externalAutoDetect = DETECTION_UARTMUX; | 730 externalAutoDetect = DETECTION_UARTMUX; |
708 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2); | 731 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2); |
732 externalInterface_CheckBaudrate(SENSOR_DIGO2); | |
709 UART_MUX_SelectAddress(MAX_MUX_CHANNEL); | 733 UART_MUX_SelectAddress(MAX_MUX_CHANNEL); |
710 uartO2_SetChannel(MAX_MUX_CHANNEL); | 734 uartO2_SetChannel(MAX_MUX_CHANNEL); |
711 activeUartChannel = MAX_MUX_CHANNEL; | 735 activeUartChannel = MAX_MUX_CHANNEL; |
712 tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX; | 736 tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX; |
713 break; | 737 break; |
714 case DETECTION_UARTMUX: if(uartO2_isSensorConnected()) | 738 case DETECTION_UARTMUX: if(uartO2_isSensorConnected()) |
715 { | 739 { |
716 uartMuxChannel = 1; | 740 uartMuxChannel = 1; |
717 tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX; | 741 tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX; |
718 foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX; | 742 foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX; |
719 } | 743 } |
720 else | 744 else |
721 { | 745 { |
722 tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_NONE; | 746 tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_NONE; |
723 } | 747 } |
724 externalAutoDetect = DETECTION_DIGO2_0; | 748 externalAutoDetect = DETECTION_DIGO2_0; |
725 uartO2_SetChannel(0); | 749 uartO2_SetChannel(0); |
726 activeUartChannel = 0; | 750 activeUartChannel = 0; |
727 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET] = SENSOR_DIGO2; | 751 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET] = SENSOR_DIGO2; |
728 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET] = UART_COMMON_INIT; | 752 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET] = UART_COMMON_INIT; |
729 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2); | 753 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2); |
730 if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) | 754 if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) |
731 { | 755 { |
732 UART_MUX_SelectAddress(0); | 756 UART_MUX_SelectAddress(0); |
733 } | 757 } |
734 break; | 758 break; |
735 case DETECTION_DIGO2_0: | 759 case DETECTION_DIGO2_0: |
736 case DETECTION_DIGO2_1: | 760 case DETECTION_DIGO2_1: |
737 case DETECTION_DIGO2_2: | 761 case DETECTION_DIGO2_2: |
738 case DETECTION_DIGO2_3: | 762 case DETECTION_DIGO2_3: |
789 case DETECTION_CO2_1: | 813 case DETECTION_CO2_1: |
790 case DETECTION_CO2_2: | 814 case DETECTION_CO2_2: |
791 case DETECTION_CO2_3: if(uartCo2_isSensorConnected()) | 815 case DETECTION_CO2_3: if(uartCo2_isSensorConnected()) |
792 { | 816 { |
793 foundSensorMap[EXT_INTERFACE_MUX_OFFSET + activeUartChannel] = SENSOR_CO2; | 817 foundSensorMap[EXT_INTERFACE_MUX_OFFSET + activeUartChannel] = SENSOR_CO2; |
818 #ifdef ENABLE_GNSS_SUPPORT | |
819 externalAutoDetect = DETECTION_GNSS_0; /* only one CO2 sensor supported */ | |
820 #else | |
794 externalAutoDetect = DETECTION_DONE; /* only one CO2 sensor supported */ | 821 externalAutoDetect = DETECTION_DONE; /* only one CO2 sensor supported */ |
822 #endif | |
795 } | 823 } |
796 else if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) | 824 else if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) |
797 { | 825 { |
798 externalInterface_CheckBaudrate(SENSOR_DIGO2); | 826 externalInterface_CheckBaudrate(SENSOR_DIGO2); |
799 UART_MUX_SelectAddress(uartMuxChannel); | 827 UART_MUX_SelectAddress(uartMuxChannel); |
806 externalAutoDetect++; | 834 externalAutoDetect++; |
807 uartMuxChannel++; | 835 uartMuxChannel++; |
808 } | 836 } |
809 else | 837 else |
810 { | 838 { |
839 | |
840 | |
841 #if defined ENABLE_SENTINEL_MODE || defined ENABLE_GNSS_SUPPORT | |
842 #ifdef ENABLE_GNSS_SUPPORT | |
843 externalAutoDetect = DETECTION_GNSS_0; | |
844 #else | |
811 #ifdef ENABLE_SENTINEL_MODE | 845 #ifdef ENABLE_SENTINEL_MODE |
812 externalAutoDetect = DETECTION_SENTINEL; | 846 externalAutoDetect = DETECTION_SENTINEL; |
847 #endif | |
848 #endif | |
813 #else | 849 #else |
814 externalAutoDetect = DETECTION_DONE; | 850 externalAutoDetect = DETECTION_DONE; |
815 #endif | 851 #endif |
816 } | 852 } |
817 #endif | 853 #endif |
854 | |
855 #ifdef ENABLE_GNSS_SUPPORT | |
856 if(externalAutoDetect == DETECTION_GNSS_0) | |
857 { | |
858 tmpSensorMap[uartMuxChannel + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE; | |
859 if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) | |
860 { | |
861 externalInterface_CheckBaudrate(SENSOR_DIGO2); | |
862 UART_MUX_SelectAddress(0); | |
863 } | |
864 activeUartChannel = 0; | |
865 tmpSensorMap[uartMuxChannel - 1 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE; | |
866 uartMuxChannel = 1; | |
867 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET] = SENSOR_GNSS; | |
868 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET] = UART_COMMON_INIT; | |
869 externalInterface_CheckBaudrate(SENSOR_GNSS); | |
870 externalInterfaceMuxReqIntervall = 200; /* iterations needed for module config */ | |
871 detectionDelayCnt = 3; | |
872 // uartGnss_SendCmd(GNSSCMD_MODE_POLL, cmdString, &cmdLength); | |
873 } | |
874 break; | |
875 case DETECTION_GNSS_0: | |
876 case DETECTION_GNSS_1: | |
877 case DETECTION_GNSS_2: | |
878 case DETECTION_GNSS_3: if(detectionDelayCnt == 0) | |
879 { | |
880 if(uartGnss_isSensorConnected()) | |
881 { | |
882 foundSensorMap[EXT_INTERFACE_MUX_OFFSET + activeUartChannel] = SENSOR_GNSS; | |
883 #ifdef ENABLE_SENTINEL_MODE | |
884 externalAutoDetect = DETECTION_SENTINEL; /* only one GNSS sensor supported */ | |
885 #else | |
886 externalAutoDetect = DETECTION_DONE; /* only one GNSS sensor supported */ | |
887 #endif | |
888 } | |
889 else if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) | |
890 { | |
891 externalInterface_CheckBaudrate(SENSOR_DIGO2); | |
892 UART_MUX_SelectAddress(uartMuxChannel); | |
893 activeUartChannel = uartMuxChannel; | |
894 tmpSensorMap[uartMuxChannel - 1 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE; | |
895 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET + uartMuxChannel] = SENSOR_CO2; | |
896 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET + uartMuxChannel] = UART_COMMON_INIT; | |
897 externalInterface_CheckBaudrate(SENSOR_CO2); | |
898 // uartGnss_SendCmd(GNSSCMD_MODE_POLL, cmdString, &cmdLength); | |
899 externalAutoDetect++; | |
900 detectionDelayCnt = 3; | |
901 uartMuxChannel++; | |
902 } | |
903 else | |
904 { | |
905 #ifdef ENABLE_SENTINEL_MODE | |
906 externalAutoDetect = DETECTION_SENTINEL; | |
907 #else | |
908 externalAutoDetect = DETECTION_DONE; | |
909 #endif | |
910 } | |
911 } | |
912 else | |
913 { | |
914 detectionDelayCnt--; | |
915 } | |
916 #endif | |
818 #ifdef ENABLE_SENTINEL_MODE | 917 #ifdef ENABLE_SENTINEL_MODE |
819 if(externalAutoDetect == DETECTION_SENTINEL) | 918 if(externalAutoDetect == DETECTION_SENTINEL) |
820 { | 919 { |
821 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET] = UART_COMMON_INIT; | 920 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET] = UART_COMMON_INIT; |
822 uartO2_SetChannel(0); | 921 uartO2_SetChannel(0); |
850 if((foundSensorMap[index] >= SENSOR_ANALOG) && (foundSensorMap[index] < SENSOR_MUX)) | 949 if((foundSensorMap[index] >= SENSOR_ANALOG) && (foundSensorMap[index] < SENSOR_MUX)) |
851 { | 950 { |
852 cntSensor++; | 951 cntSensor++; |
853 } | 952 } |
854 | 953 |
855 if((foundSensorMap[index] == SENSOR_DIGO2) || (foundSensorMap[index] == SENSOR_CO2)) | 954 if((foundSensorMap[index] == SENSOR_DIGO2) || (foundSensorMap[index] == SENSOR_CO2) || (foundSensorMap[index] == SENSOR_GNSS)) |
856 { | 955 { |
857 cntUARTSensor++; | 956 cntUARTSensor++; |
858 } | 957 } |
859 #ifdef ENABLE_SENTINEL_MODE | 958 #ifdef ENABLE_SENTINEL_MODE |
860 if(foundSensorMap[index] == SENSOR_SENTINEL) /* The Sentinel has a fixed setup */ | 959 if(foundSensorMap[index] == SENSOR_SENTINEL) /* The Sentinel has a fixed setup */ |
917 case EXT_INTERFACE_COPY_SENSORMAP: if(externalAutoDetect == DETECTION_OFF) | 1016 case EXT_INTERFACE_COPY_SENSORMAP: if(externalAutoDetect == DETECTION_OFF) |
918 { | 1017 { |
919 memcpy(SensorMap, MasterSensorMap, sizeof(MasterSensorMap)); | 1018 memcpy(SensorMap, MasterSensorMap, sizeof(MasterSensorMap)); |
920 for(index = 0; index < EXT_INTERFACE_SENSOR_CNT; index++) | 1019 for(index = 0; index < EXT_INTERFACE_SENSOR_CNT; index++) |
921 { | 1020 { |
922 if((SensorMap[index] == SENSOR_DIGO2) || (SensorMap[index] == SENSOR_CO2)) | 1021 if((SensorMap[index] == SENSOR_DIGO2) || (SensorMap[index] == SENSOR_CO2) || (SensorMap[index] == SENSOR_GNSS)) |
923 { | 1022 { |
924 cntUARTSensor++; | 1023 cntUARTSensor++; |
925 } | 1024 } |
926 } | 1025 } |
927 externalInface_MapUartToLegacyADC(SensorMap); | 1026 externalInface_MapUartToLegacyADC(SensorMap); |
957 index++; | 1056 index++; |
958 if(index == MAX_MUX_CHANNEL) | 1057 if(index == MAX_MUX_CHANNEL) |
959 { | 1058 { |
960 index = 0; | 1059 index = 0; |
961 } | 1060 } |
962 if(((pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_DIGO2) || (pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_CO2)) | 1061 if(((pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_DIGO2) || (pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_CO2) || (pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_GNSS)) |
963 && (index != activeUartChannel)) | 1062 && (index != activeUartChannel)) |
964 { | 1063 { |
965 newChannel = index; | 1064 newChannel = index; |
966 break; | 1065 break; |
967 } | 1066 } |
974 { | 1073 { |
975 uint32_t newBaudrate = 0; | 1074 uint32_t newBaudrate = 0; |
976 | 1075 |
977 switch(sensorType) | 1076 switch(sensorType) |
978 { | 1077 { |
1078 case SENSOR_GNSS: | |
979 case SENSOR_SENTINEL: | 1079 case SENSOR_SENTINEL: |
980 case SENSOR_CO2: newBaudrate = 9600; | 1080 case SENSOR_CO2: newBaudrate = 9600; |
981 break; | 1081 break; |
982 case SENSOR_DIGO2: | 1082 case SENSOR_DIGO2: |
983 default: newBaudrate = 19200; | 1083 default: newBaudrate = 19200; |
996 static uint32_t TriggerTick = 0; | 1096 static uint32_t TriggerTick = 0; |
997 uint8_t index = 0; | 1097 uint8_t index = 0; |
998 static uint8_t timeToTrigger = 0; | 1098 static uint8_t timeToTrigger = 0; |
999 uint32_t tick = HAL_GetTick(); | 1099 uint32_t tick = HAL_GetTick(); |
1000 uint8_t *pmap = externalInterface_GetSensorMapPointer(0); | 1100 uint8_t *pmap = externalInterface_GetSensorMapPointer(0); |
1101 uint8_t forceMuxChannel = 0; | |
1001 | 1102 |
1002 | 1103 |
1003 if(externalInterfaceMuxReqIntervall != 0xFFFF) | 1104 if(externalInterfaceMuxReqIntervall != 0xFFFF) |
1004 { | 1105 { |
1005 UART_ReadData(pmap[activeSensorId]); | |
1006 | |
1007 if(activeUartChannel == 0xFF) | 1106 if(activeUartChannel == 0xFF) |
1008 { | 1107 { |
1009 MX_USART1_UART_Init(); | 1108 MX_USART1_UART_Init(); |
1010 activeUartChannel = ExternalInterface_SelectUsedMuxChannel(0); | 1109 activeUartChannel = ExternalInterface_SelectUsedMuxChannel(0); |
1011 uartO2_SetChannel(activeUartChannel); | 1110 uartO2_SetChannel(activeUartChannel); |
1012 | 1111 |
1013 switch(pmap[activeUartChannel + EXT_INTERFACE_MUX_OFFSET]) | 1112 switch(pmap[activeUartChannel + EXT_INTERFACE_MUX_OFFSET]) |
1014 { | 1113 { |
1015 case SENSOR_SENTINEL: externalInterface_CheckBaudrate(SENSOR_SENTINEL); | 1114 case SENSOR_DIGO2: |
1115 case SENSOR_GNSS: | |
1116 case SENSOR_CO2: | |
1117 case SENSOR_SENTINEL: externalInterface_CheckBaudrate(pmap[activeUartChannel + EXT_INTERFACE_MUX_OFFSET]); | |
1016 break; | 1118 break; |
1017 case SENSOR_CO2: externalInterface_CheckBaudrate(SENSOR_CO2); | 1119 default: externalInterface_CheckBaudrate(SENSOR_DIGO2); |
1018 break; | 1120 break; |
1019 default: | |
1020 case SENSOR_DIGO2: externalInterface_CheckBaudrate(SENSOR_DIGO2); | |
1021 break; | |
1022 } | 1121 } |
1023 if(pmap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) | 1122 if(pmap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) |
1024 { | 1123 { |
1124 HAL_Delay(10); /* make sure MUX is available for reception after wakeup */ | |
1025 UART_MUX_SelectAddress(activeUartChannel); | 1125 UART_MUX_SelectAddress(activeUartChannel); |
1026 } | 1126 } |
1027 } | 1127 } |
1028 | 1128 |
1129 if(externalInterface_SensorState[activeSensorId] != UART_COMMON_INIT) | |
1130 { | |
1131 UART_ReadData(pmap[activeSensorId]); | |
1132 UART_WriteData(); | |
1133 } | |
1029 if(externalInterface_SensorState[activeSensorId] == UART_COMMON_INIT) | 1134 if(externalInterface_SensorState[activeSensorId] == UART_COMMON_INIT) |
1030 { | 1135 { |
1031 lastRequestTick = tick; | 1136 lastRequestTick = tick; |
1032 TriggerTick = tick - 10; /* just to make sure control is triggered */ | 1137 TriggerTick = tick - 10; /* just to make sure control is triggered */ |
1033 timeToTrigger = 1; | 1138 timeToTrigger = 1; |
1054 | 1159 |
1055 if((externalInterface_SensorState[activeSensorId] == UART_O2_REQ_O2) /* timeout */ | 1160 if((externalInterface_SensorState[activeSensorId] == UART_O2_REQ_O2) /* timeout */ |
1056 || (externalInterface_SensorState[activeSensorId] == UART_O2_REQ_RAW) | 1161 || (externalInterface_SensorState[activeSensorId] == UART_O2_REQ_RAW) |
1057 || (externalInterface_SensorState[activeSensorId] == UART_CO2_OPERATING)) | 1162 || (externalInterface_SensorState[activeSensorId] == UART_CO2_OPERATING)) |
1058 { | 1163 { |
1164 forceMuxChannel = 1; | |
1059 switch(pmap[activeSensorId]) | 1165 switch(pmap[activeSensorId]) |
1060 { | 1166 { |
1061 case SENSOR_DIGO2: setExternalInterfaceChannel(activeSensorId,0.0); | 1167 case SENSOR_DIGO2: setExternalInterfaceChannel(activeSensorId,0.0); |
1062 break; | 1168 break; |
1063 case SENSOR_CO2: externalInterface_SetCO2Value(0.0); | 1169 case SENSOR_CO2: externalInterface_SetCO2Value(0.0); |
1071 if(pmap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) /* select next sensor if mux is connected */ | 1177 if(pmap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) /* select next sensor if mux is connected */ |
1072 { | 1178 { |
1073 if(activeUartChannel < MAX_MUX_CHANNEL) | 1179 if(activeUartChannel < MAX_MUX_CHANNEL) |
1074 { | 1180 { |
1075 index = ExternalInterface_SelectUsedMuxChannel(activeUartChannel); | 1181 index = ExternalInterface_SelectUsedMuxChannel(activeUartChannel); |
1076 if(index != activeUartChannel) | 1182 if((index != activeUartChannel) || (forceMuxChannel)) |
1077 { | 1183 { |
1184 forceMuxChannel = 0; | |
1078 timeToTrigger = 100; | 1185 timeToTrigger = 100; |
1079 activeUartChannel = index; | 1186 activeUartChannel = index; |
1080 if((pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_DIGO2) | 1187 if((pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_DIGO2) |
1081 || (pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_CO2)) | 1188 || (pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_CO2) |
1189 || (pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_GNSS)) | |
1082 { | 1190 { |
1083 uartO2_SetChannel(activeUartChannel); | 1191 uartO2_SetChannel(activeUartChannel); |
1084 externalInterface_CheckBaudrate(SENSOR_MUX); | 1192 externalInterface_CheckBaudrate(SENSOR_MUX); |
1085 UART_MUX_SelectAddress(activeUartChannel); | 1193 UART_MUX_SelectAddress(activeUartChannel); |
1086 externalInterface_CheckBaudrate(pmap[activeUartChannel + EXT_INTERFACE_MUX_OFFSET]); | 1194 externalInterface_CheckBaudrate(pmap[activeUartChannel + EXT_INTERFACE_MUX_OFFSET]); |
1103 break; | 1211 break; |
1104 #ifdef ENABLE_CO2_SUPPORT | 1212 #ifdef ENABLE_CO2_SUPPORT |
1105 case SENSOR_CO2: uartCo2_Control(); | 1213 case SENSOR_CO2: uartCo2_Control(); |
1106 break; | 1214 break; |
1107 #endif | 1215 #endif |
1216 #ifdef ENABLE_GNSS_SUPPORT | |
1217 case SENSOR_GNSS: uartGnss_Control(); | |
1218 break; | |
1219 #endif | |
1108 #ifdef ENABLE_SENTINEL_MODE | 1220 #ifdef ENABLE_SENTINEL_MODE |
1109 case SENSOR_SENTINEL: uartSentinel_Control(); | 1221 case SENSOR_SENTINEL: uartSentinel_Control(); |
1110 break; | 1222 break; |
1111 #endif | 1223 #endif |
1112 default: | 1224 default: |