Mercurial > public > ostc4
annotate Small_CPU/Src/externalInterface.c @ 928:9b7859554beb Evo_2_23 tip
Cleanup Internal Uart:
The compile switches have been updated to allow GNSS data flow if new GPIO config is available or if GNSS is enabled for the external UART.
author | Ideenmodellierer |
---|---|
date | Tue, 26 Nov 2024 21:30:06 +0100 |
parents | eb4109d7d1e9 |
children |
rev | line source |
---|---|
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
1 /** |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
2 ****************************************************************************** |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
3 * @file externalInterface.c |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
4 * @author heinrichs weikamp gmbh |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
5 * @version V0.0.1 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
6 * @date 07-Nov-2020 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
7 * @brief Interface functionality to proceed external analog signal via i2c connection |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
8 * |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
9 @verbatim |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
10 ============================================================================== |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
11 ##### stm32f4xx_hal_i2c.c modification ##### |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
12 ============================================================================== |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
13 The LTC2942 requires an repeated start condition without stop condition |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
14 for data reception. |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
15 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
16 @endverbatim |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
17 ****************************************************************************** |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
18 * @attention |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
19 * |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
20 * <h2><center>© COPYRIGHT(c) 2014 heinrichs weikamp</center></h2> |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
21 * |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
22 ****************************************************************************** |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
23 */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
24 /* Includes ------------------------------------------------------------------*/ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
25 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
26 #include <math.h> |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
27 #include <string.h> |
794 | 28 #include "data_central.h" |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
29 #include "i2c.h" |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
30 #include "externalInterface.h" |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
31 #include "scheduler.h" |
662 | 32 #include "uart.h" |
33 #include "data_exchange.h" | |
747
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
34 #include "pressure.h" |
794 | 35 #include "uartProtocol_O2.h" |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
36 #include "uartProtocol_Co2.h" |
842
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
37 #include "uartProtocol_Sentinel.h" |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
38 #include "uartProtocol_GNSS.h" |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
39 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
40 extern SGlobal global; |
662 | 41 extern UART_HandleTypeDef huart1; |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
42 |
921 | 43 #define ADC_ANSWER_LENGTH (5u) /* 3424 will provide addr + 4 data bytes */ |
44 #define ADC_TIMEOUT (10u) /* conversion stuck for unknown reason => restart */ | |
45 #define ADC_REF_VOLTAGE_MV (2048.0f) /* reference voltage of MPC3424*/ | |
46 #define ADC_CYCLE_INTERVAL_MS (1000u) /* start adc read out once per second*/ | |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
47 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
48 #define ADC_START_CONVERSION (0x80) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
49 #define ADC_GAIN_4 (0x02) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
50 #define ADC_GAIN_4_VALUE (4.0f) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
51 #define ADC_GAIN_8 (0x03) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
52 #define ADC_GAIN_8_VALUE (8.0f) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
53 #define ADC_RESOLUTION_16BIT (0x08) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
54 #define ADC_RESOLUTION_16BIT_VALUE (16u) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
55 #define ADC_RESOLUTION_18BIT (0x0C) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
56 #define ADC_RESOLUTION_18BIT_VALUE (18u) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
57 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
58 #define ANSWER_CONFBYTE_INDEX (4u) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
59 |
747
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
60 #define LOOKUP_CO2_CORR_TABLE_SCALE (1000u) |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
61 #define LOOKUP_CO2_CORR_TABLE_MAX (30000u) |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
62 |
794 | 63 #define REQUEST_INT_SENSOR_MS (1500) /* Minimum time interval for cyclic sensor data requests per sensor (UART mux) */ |
64 #define COMMAND_TX_DELAY (30u) /* The time the sensor needs to recover from a invalid command request */ | |
65 #define TIMEOUT_SENSOR_ANSWER (300) /* Time till a request is repeated if no answer was received */ | |
66 | |
67 #define activeSensorId (activeUartChannel + EXT_INTERFACE_MUX_OFFSET) /* Used if UART channels are applied to Sensor map */ | |
68 | |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
69 static uint8_t activeChannel = 0; /* channel which is in request */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
70 static uint8_t recBuf[ADC_ANSWER_LENGTH]; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
71 static uint8_t timeoutCnt = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
72 static uint8_t externalInterfacePresent = 0; |
861 | 73 static uint8_t delayAdcConversion = 0; |
921 | 74 static uint32_t startTickADC = 0; |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
75 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
76 float externalChannel_mV[MAX_ADC_CHANNEL]; |
662 | 77 static uint8_t externalV33_On = 0; |
691 | 78 static uint8_t externalADC_On = 0; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
79 static uint8_t externalUART_Protocol = 0; |
662 | 80 static uint16_t externalCO2Value; |
81 static uint16_t externalCO2SignalStrength; | |
794 | 82 static uint16_t externalCO2Status = 0; |
83 static float externalCO2Scale = 0.0; | |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
84 |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
85 static uint8_t lastSensorDataId = 0; |
794 | 86 static SSensorDataDiveO2 sensorDataDiveO2[EXT_INTERFACE_SENSOR_CNT]; |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
87 static externalInterfaceAutoDetect_t externalAutoDetect = DETECTION_OFF; |
747
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
88 static externalInterfaceSensorType SensorMap[EXT_INTERFACE_SENSOR_CNT] ={ SENSOR_OPTIC, SENSOR_OPTIC, SENSOR_OPTIC, SENSOR_NONE, SENSOR_NONE}; |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
89 static externalInterfaceSensorType tmpSensorMap[EXT_INTERFACE_SENSOR_CNT]; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
90 static externalInterfaceSensorType MasterSensorMap[EXT_INTERFACE_SENSOR_CNT]; |
794 | 91 static externalInterfaceSensorType foundSensorMap[EXT_INTERFACE_SENSOR_CNT]; |
92 static uint8_t Mux2ADCMap[MAX_ADC_CHANNEL]; | |
93 static uint8_t externalInterface_SensorState[EXT_INTERFACE_SENSOR_CNT]; | |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
94 |
747
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
95 static float LookupCO2PressureCorrection[LOOKUP_CO2_CORR_TABLE_MAX / LOOKUP_CO2_CORR_TABLE_SCALE]; /* lookup table for pressure compensation values */ |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
96 |
804 | 97 static uint16_t externalInterfaceMuxReqIntervall = 0xffff; /* delay between switching from one MUX channel to the next */ |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
98 static uint8_t activeUartChannel = 0xff; |
804 | 99 |
100 | |
101 static void externalInface_MapUartToLegacyADC(uint8_t* pMap); | |
809 | 102 static void externalInterface_CheckBaudrate(uint8_t sensorType); |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
103 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
104 void externalInterface_Init(void) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
105 { |
747
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
106 uint16_t index; |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
107 uint16_t coeff; |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
108 activeChannel = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
109 timeoutCnt = 0; |
861 | 110 delayAdcConversion = 0; |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
111 if(externalInterface_StartConversion(activeChannel) == HAL_OK) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
112 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
113 externalInterfacePresent = 1; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
114 global.deviceDataSendToMaster.hw_Info.extADC = 1; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
115 } |
559 | 116 global.deviceDataSendToMaster.hw_Info.checkADC = 1; |
662 | 117 |
804 | 118 |
794 | 119 |
747
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
120 /* Create a lookup table based on GSS application note AN001: PRESSURE COMPENSATION OF A CO2 SENSOR */ |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
121 /* The main purpose of the sensor in the dive application is to be a warning indicator */ |
753 | 122 /* => no exact values necessary => a lookup table with 1000ppm scaling should be sufficient */ |
747
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
123 LookupCO2PressureCorrection [0] = -0.0014; |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
124 for(index = 1; index < (LOOKUP_CO2_CORR_TABLE_MAX / LOOKUP_CO2_CORR_TABLE_SCALE); index++) |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
125 { |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
126 coeff = index * LOOKUP_CO2_CORR_TABLE_SCALE; |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
127 LookupCO2PressureCorrection[index] = 2.811*pow(10,-38)*pow(coeff,6)- 9.817*pow(10,-32)*pow(coeff,5)+1.304*pow(10,-25)*pow(coeff,4)-8.216*pow(10,-20)*pow(coeff,3)+2.311*pow(10,-14)*pow(coeff,2) - 2.195*pow(10,-9)*coeff - 1.471*pow(10,-3); |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
128 } |
738
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
129 externalInterface_InitDatastruct(); |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
130 } |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
131 |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
132 void externalInterface_InitDatastruct(void) |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
133 { |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
134 uint8_t index = 0; |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
135 /* init data values */ |
804 | 136 externalUART_Protocol = 0; |
662 | 137 externalCO2Value = 0; |
138 externalCO2SignalStrength = 0; | |
139 externalCO2Status = 0; | |
804 | 140 externalCO2Scale = 0.0; |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
141 externalAutoDetect = DETECTION_OFF; |
738
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
142 |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
143 for(index = 0; index < MAX_ADC_CHANNEL; index++) |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
144 { |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
145 externalChannel_mV[index] = 0.0; |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
146 } |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
147 memset(externalInterface_SensorState,UART_COMMON_INIT,sizeof(externalInterface_SensorState)); |
804 | 148 externalInface_MapUartToLegacyADC(SensorMap); |
149 activeUartChannel = 0xFF; | |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
150 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
151 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
152 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
153 uint8_t externalInterface_StartConversion(uint8_t channel) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
154 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
155 uint8_t retval = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
156 uint8_t confByte = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
157 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
158 if(channel < MAX_ADC_CHANNEL) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
159 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
160 confByte = ADC_START_CONVERSION | ADC_RESOLUTION_16BIT | ADC_GAIN_8; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
161 confByte |= channel << 5; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
162 retval = I2C_Master_Transmit(DEVICE_EXTERNAL_ADC, &confByte, 1); |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
163 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
164 return retval; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
165 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
166 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
167 /* Check if conversion is done and trigger measurement of next channel */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
168 uint8_t externalInterface_ReadAndSwitch() |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
169 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
170 uint8_t retval = EXTERNAL_ADC_NO_DATA; |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
171 uint8_t nextChannel; |
731 | 172 uint8_t* psensorMap = externalInterface_GetSensorMapPointer(0); |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
173 |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
174 if(externalADC_On) |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
175 { |
921 | 176 if(time_elapsed_ms(startTickADC, HAL_GetTick()) > ADC_CYCLE_INTERVAL_MS) |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
177 { |
921 | 178 if(delayAdcConversion) |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
179 { |
921 | 180 if(UART_isComActive(activeUartChannel) == 0) |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
181 { |
921 | 182 externalInterface_StartConversion(activeChannel); |
183 delayAdcConversion = 0; | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
184 } |
921 | 185 } |
186 else if(I2C_Master_Receive(DEVICE_EXTERNAL_ADC, recBuf, ADC_ANSWER_LENGTH) == HAL_OK) | |
187 { | |
188 if((recBuf[ANSWER_CONFBYTE_INDEX] & ADC_START_CONVERSION) == 0) /* !ready set => received data contains new value */ | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
189 { |
921 | 190 retval = activeChannel; /* return channel number providing new data */ |
191 nextChannel = activeChannel + 1; | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
192 if(nextChannel == MAX_ADC_CHANNEL) |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
193 { |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
194 nextChannel = 0; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
195 } |
921 | 196 |
197 while((psensorMap[nextChannel] != SENSOR_ANALOG) && (nextChannel != activeChannel)) | |
198 { | |
199 if(nextChannel == MAX_ADC_CHANNEL) | |
200 { | |
201 nextChannel = 0; | |
202 startTickADC = HAL_GetTick(); | |
203 } | |
204 else | |
205 { | |
206 nextChannel++; | |
207 } | |
208 } | |
209 | |
210 activeChannel = nextChannel; | |
211 if(activeChannel == 0) | |
212 { | |
213 delayAdcConversion = 1; /* wait for next cycle interval */ | |
214 } | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
215 else |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
216 { |
921 | 217 if(UART_isComActive(activeUartChannel) == 0) |
218 { | |
219 externalInterface_StartConversion(activeChannel); | |
220 } | |
221 else | |
222 { | |
223 delayAdcConversion = 1; | |
224 } | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
225 } |
921 | 226 timeoutCnt = 0; |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
227 } |
921 | 228 } |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
229 |
861 | 230 if(timeoutCnt++ >= ADC_TIMEOUT) |
231 { | |
232 externalInterface_StartConversion(activeChannel); | |
233 delayAdcConversion = 0; | |
234 timeoutCnt = 0; | |
581
011d8f9f5ddb
Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents:
559
diff
changeset
|
235 } |
921 | 236 } |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
237 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
238 return retval; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
239 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
240 float externalInterface_CalculateADCValue(uint8_t channel) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
241 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
242 int32_t rawvalue = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
243 float retValue = 0.0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
244 if(channel < MAX_ADC_CHANNEL) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
245 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
246 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
247 rawvalue = ((recBuf[0] << 16) | (recBuf[1] << 8) | (recBuf[2])); |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
248 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
249 switch(recBuf[3] & 0x0C) /* confbyte => Resolution bits*/ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
250 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
251 case ADC_RESOLUTION_16BIT: rawvalue = rawvalue >> 8; /* only 2 databytes received shift out confbyte*/ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
252 if(rawvalue & (0x1 << (ADC_RESOLUTION_16BIT_VALUE-1))) /* MSB set => negative number */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
253 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
254 rawvalue |= 0xFFFF0000; /* set MSB for int32 */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
255 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
256 else |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
257 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
258 rawvalue &= 0x0000FFFF; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
259 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
260 externalChannel_mV[channel] = ADC_REF_VOLTAGE_MV * 2.0 / (float) pow(2,ADC_RESOLUTION_16BIT_VALUE); /* calculate bit resolution */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
261 break; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
262 case ADC_RESOLUTION_18BIT: if(rawvalue & (0x1 << (ADC_RESOLUTION_18BIT_VALUE-1))) /* MSB set => negative number */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
263 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
264 rawvalue |= 0xFFFE0000; /* set MSB for int32 */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
265 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
266 externalChannel_mV[channel] = ADC_REF_VOLTAGE_MV * 2.0 / (float) pow(2,ADC_RESOLUTION_18BIT_VALUE); /* calculate bit resolution */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
267 break; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
268 default: rawvalue = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
269 break; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
270 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
271 externalChannel_mV[channel] = externalChannel_mV[channel] * rawvalue / ADC_GAIN_8_VALUE; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
272 retValue = externalChannel_mV[channel]; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
273 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
274 return retValue; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
275 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
276 float getExternalInterfaceChannel(uint8_t channel) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
277 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
278 float retval = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
279 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
280 if(channel < MAX_ADC_CHANNEL) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
281 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
282 retval = externalChannel_mV[channel]; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
283 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
284 return retval; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
285 } |
662 | 286 |
691 | 287 uint8_t setExternalInterfaceChannel(uint8_t channel, float value) |
288 { | |
289 uint8_t retval = 0; | |
794 | 290 uint8_t localId = channel; |
291 uint8_t index = 0; | |
691 | 292 |
794 | 293 if(localId >= MAX_ADC_CHANNEL) /* at the moment sensor visualization is focused on the three ADC channels => map Mux sensors */ |
691 | 294 { |
794 | 295 for(index = 0; index < MAX_ADC_CHANNEL; index++) |
296 { | |
297 if(Mux2ADCMap[index] == localId) | |
298 { | |
299 localId = index; | |
300 break; | |
301 } | |
302 } | |
303 } | |
304 | |
305 if(localId < MAX_ADC_CHANNEL) | |
306 { | |
307 externalChannel_mV[localId] = value; | |
691 | 308 retval = 1; |
309 } | |
310 return retval; | |
311 } | |
312 | |
662 | 313 void externalInterface_InitPower33(void) |
314 { | |
315 GPIO_InitTypeDef GPIO_InitStructure; | |
316 | |
317 GPIO_InitStructure.Pin = GPIO_PIN_7; | |
318 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
319 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
320 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
321 HAL_GPIO_Init(GPIOC, &GPIO_InitStructure); | |
322 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET); | |
323 } | |
324 | |
325 | |
326 uint8_t externalInterface_isEnabledPower33() | |
327 { | |
328 return externalV33_On; | |
329 } | |
691 | 330 |
331 uint8_t externalInterface_isEnabledADC() | |
332 { | |
333 return externalADC_On; | |
334 } | |
335 | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
336 uint8_t externalInterface_GetUARTProtocol() |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
337 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
338 return externalUART_Protocol; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
339 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
340 |
662 | 341 void externalInterface_SwitchPower33(uint8_t state) |
342 { | |
343 if(state != externalV33_On) | |
344 { | |
345 if(state) | |
346 { | |
347 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_RESET); | |
348 externalV33_On = 1; | |
349 } | |
350 else | |
351 { | |
731 | 352 if(externalAutoDetect == DETECTION_OFF) |
353 { | |
354 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET); | |
355 externalV33_On = 0; | |
356 externalInterface_SetCO2Value(0); | |
357 externalInterface_SetCO2SignalStrength(0); | |
358 } | |
662 | 359 } |
360 } | |
361 } | |
691 | 362 void externalInterface_SwitchADC(uint8_t state) |
363 { | |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
364 uint8_t loop = 0; |
691 | 365 if((state) && (externalInterfacePresent)) |
366 { | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
367 if(externalADC_On == 0) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
368 { |
921 | 369 startTickADC = HAL_GetTick(); |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
370 activeChannel = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
371 externalInterface_StartConversion(activeChannel); |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
372 externalADC_On = 1; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
373 } |
691 | 374 } |
375 else | |
376 { | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
377 if(externalAutoDetect == DETECTION_OFF) /* block deactivation requests if auto detection is active */ |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
378 { |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
379 externalADC_On = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
380 for(loop = 0; loop < MAX_ADC_CHANNEL; loop++) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
381 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
382 externalChannel_mV[loop] = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
383 } |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
384 } |
691 | 385 } |
386 } | |
662 | 387 |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
388 void externalInterface_SwitchUART(uint8_t protocol) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
389 { |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
390 switch(protocol) |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
391 { |
839 | 392 case EXT_INTERFACE_UART_OFF: |
393 case EXT_INTERFACE_UART_CO2: | |
394 case EXT_INTERFACE_UART_O2: | |
395 case EXT_INTERFACE_UART_SENTINEL: | |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
396 case EXT_INTERFACE_UART_GNSS: |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
397 if((externalAutoDetect <= DETECTION_START) |
839 | 398 || ((protocol == EXT_INTERFACE_UART_O2) && (externalAutoDetect >= DETECTION_UARTMUX) && (externalAutoDetect <= DETECTION_DIGO2_3)) |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
399 |
746 | 400 #ifdef ENABLE_CO2_SUPPORT |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
401 || ((externalAutoDetect >= DETECTION_CO2_0) && (externalAutoDetect <= DETECTION_CO2_3)) |
746 | 402 #endif |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
403 #ifdef ENABLE_GNSS_SUPPORT |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
404 || ((externalAutoDetect >= DETECTION_GNSS_0) && (externalAutoDetect <= DETECTION_GNSS_3)) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
405 #endif |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
406 |
746 | 407 #ifdef ENABLE_SENTINEL_MODE |
839 | 408 || ((protocol == EXT_INTERFACE_UART_SENTINEL) && (externalAutoDetect == DETECTION_SENTINEL)) |
746 | 409 #endif |
410 ) | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
411 { |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
412 lastSensorDataId = 0; |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
413 externalUART_Protocol = protocol; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
414 MX_USART1_UART_DeInit(); |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
415 if( protocol != 0) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
416 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
417 MX_USART1_UART_Init(); |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
418 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
419 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
420 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
421 default: |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
422 break; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
423 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
424 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
425 |
794 | 426 uint8_t externalInterface_GetActiveUartSensor() |
427 { | |
428 return activeUartChannel; | |
429 } | |
430 | |
431 void externalInterface_SetSensorState(uint8_t sensorIdx, uint8_t state) | |
432 { | |
433 if(sensorIdx < EXT_INTERFACE_SENSOR_CNT) | |
434 { | |
435 externalInterface_SensorState[sensorIdx] = state; | |
436 } | |
437 } | |
438 | |
439 uint8_t externalInterface_GetSensorState(uint8_t sensorIdx) | |
440 { | |
441 uint8_t ret = COMMON_SENSOR_STATE_INVALID; | |
442 if(sensorIdx < EXT_INTERFACE_SENSOR_CNT) | |
443 { | |
444 ret = externalInterface_SensorState[sensorIdx]; | |
445 } | |
446 return ret; | |
447 } | |
448 | |
449 /* The supported sensors from GSS have different scaling factors depending on their accuracy. The factor may be read out of the sensor */ | |
450 void externalInterface_SetCO2Scale(float CO2Scale) | |
451 { | |
452 if((CO2Scale == 10) || (CO2Scale == 100)) | |
453 { | |
454 externalCO2Scale = CO2Scale; | |
455 } | |
456 } | |
457 float externalInterface_GetCO2Scale() | |
458 { | |
459 return externalCO2Scale; | |
460 } | |
461 | |
662 | 462 void externalInterface_SetCO2Value(uint16_t CO2_ppm) |
463 { | |
794 | 464 float local_ppm = CO2_ppm * externalCO2Scale; |
747
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
465 |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
466 #ifndef ENABLE_EXTERNAL_PRESSURE |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
467 float local_corr = 0.0; |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
468 |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
469 if (local_ppm >= LOOKUP_CO2_CORR_TABLE_MAX) |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
470 { |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
471 local_corr = -0.0014; |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
472 } |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
473 else |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
474 { |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
475 local_corr = LookupCO2PressureCorrection[((uint16_t) (local_ppm / LOOKUP_CO2_CORR_TABLE_SCALE))]; |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
476 } |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
477 local_ppm = local_ppm / (1.0 + (local_corr * (get_surface_mbar() - get_pressure_mbar()))); |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
478 #else |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
479 /* The external pressure value is passed via ADC channel2 and calibration is done at firmware => just forward sensor data */ |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
480 /* compensation is done at firmware side. This is for testing only. Take care the the same algorithm is taken as used for the lookup table */ |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
481 #endif |
794 | 482 externalCO2Value = local_ppm / externalCO2Scale; |
662 | 483 } |
484 | |
485 void externalInterface_SetCO2SignalStrength(uint16_t LED_qa) | |
486 { | |
487 externalCO2SignalStrength = LED_qa; | |
488 } | |
489 | |
490 uint16_t externalInterface_GetCO2Value(void) | |
491 { | |
492 return externalCO2Value; | |
493 } | |
494 | |
495 uint16_t externalInterface_GetCO2SignalStrength(void) | |
496 { | |
497 return externalCO2SignalStrength; | |
498 } | |
499 | |
500 | |
501 void externalInterface_SetCO2State(uint16_t state) | |
502 { | |
503 externalCO2Status = state; | |
504 } | |
505 | |
506 uint16_t externalInterface_GetCO2State(void) | |
507 { | |
508 return externalCO2Status; | |
509 } | |
510 | |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
511 |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
512 uint8_t externalInterface_GetSensorData(uint8_t sensorId, uint8_t* pDataStruct) |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
513 { |
794 | 514 uint8_t index = 0; |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
515 uint8_t localId = sensorId; |
786 | 516 if(localId == 0xFF) |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
517 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
518 localId = lastSensorDataId; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
519 } |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
520 |
794 | 521 if((pDataStruct != NULL) && (localId <= EXT_INTERFACE_SENSOR_CNT)) |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
522 { |
786 | 523 memcpy(pDataStruct, &sensorDataDiveO2[localId], sizeof(SSensorDataDiveO2)); |
524 } | |
525 else | |
526 { | |
527 localId = 0xFF; | |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
528 } |
794 | 529 if(localId > MAX_ADC_CHANNEL) /* at the moment sensor visualization is focused on the three ADC channels => map Mux sensors */ |
530 { | |
531 for(index = 0; index < MAX_ADC_CHANNEL; index++) | |
532 { | |
533 if(Mux2ADCMap[index] == localId) | |
534 { | |
535 localId = index; | |
536 } | |
537 } | |
538 } | |
539 | |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
540 return localId; |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
541 } |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
542 |
786 | 543 void externalInterface_SetSensorData(uint8_t sensorId, uint8_t* pDataStruct) |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
544 { |
794 | 545 uint8_t index = 0; |
546 | |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
547 if(pDataStruct != NULL) |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
548 { |
794 | 549 if((sensorId != 0xFF) && (sensorId < EXT_INTERFACE_SENSOR_CNT)) |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
550 { |
786 | 551 memcpy(&sensorDataDiveO2[sensorId], pDataStruct, sizeof(SSensorDataDiveO2)); |
552 lastSensorDataId = sensorId; | |
804 | 553 if(sensorId >= MAX_ADC_CHANNEL) |
794 | 554 { |
804 | 555 for(index = 0; index < MAX_ADC_CHANNEL; index++) |
794 | 556 { |
804 | 557 if(Mux2ADCMap[index] == sensorId) |
558 { | |
559 memcpy(&sensorDataDiveO2[index], pDataStruct, sizeof(SSensorDataDiveO2)); | |
560 lastSensorDataId = index; | |
561 break; | |
562 } | |
794 | 563 } |
564 } | |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
565 } |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
566 else |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
567 { |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
568 memset(&sensorDataDiveO2,0,sizeof(sensorDataDiveO2)); |
786 | 569 lastSensorDataId = 0xFF; |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
570 } |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
571 } |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
572 } |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
573 |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
574 void externalInface_SetSensorMap(uint8_t* pMap) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
575 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
576 if(pMap != NULL) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
577 { |
794 | 578 memcpy(MasterSensorMap, pMap, EXT_INTERFACE_SENSOR_CNT); /* the map is not directly copied. Copy is done via cmd request */ |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
579 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
580 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
581 } |
804 | 582 |
583 void externalInface_MapUartToLegacyADC(uint8_t* pMap) | |
584 { | |
585 uint8_t index, index2; | |
586 | |
587 memset(Mux2ADCMap,0xFF, sizeof(Mux2ADCMap)); | |
588 | |
589 for(index2 = 0; index2 < MAX_ADC_CHANNEL; index2++) /* Unmap old mirror instances */ | |
590 { | |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
591 if((pMap[index2] == SENSOR_DIGO2M) || (pMap[index2] == SENSOR_CO2M) || (pMap[index2] == SENSOR_GNSSM)) |
804 | 592 { |
593 pMap[index2] = SENSOR_NONE; | |
594 } | |
595 } | |
596 | |
597 /* Map Mux O2 sensors to ADC Slot if ADC slot is not in use */ | |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
598 for(index = EXT_INTERFACE_MUX_OFFSET; index < EXT_INTERFACE_SENSOR_CNT-1; index++) |
804 | 599 { |
600 if(pMap[index] == SENSOR_DIGO2) | |
601 { | |
602 for(index2 = 0; index2 < MAX_ADC_CHANNEL; index2++) | |
603 { | |
604 if(pMap[index2] == SENSOR_NONE) | |
605 { | |
606 pMap[index2] = SENSOR_DIGO2M; /* store a mirror instance needed for visualization */ | |
607 Mux2ADCMap[index2] = index; | |
608 break; | |
609 } | |
610 } | |
611 } | |
612 } | |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
613 for(index = EXT_INTERFACE_MUX_OFFSET; index < EXT_INTERFACE_SENSOR_CNT-1; index++) |
804 | 614 { |
615 if(pMap[index] == SENSOR_CO2) | |
616 { | |
617 for(index2 = 0; index2 < MAX_ADC_CHANNEL; index2++) | |
618 { | |
619 if(pMap[index2] == SENSOR_NONE) | |
620 { | |
621 pMap[index2] = SENSOR_CO2M; /* store a mirror instance needed for visualization */ | |
622 Mux2ADCMap[index2] = index; | |
623 break; | |
624 } | |
625 } | |
626 } | |
627 } | |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
628 for(index = EXT_INTERFACE_MUX_OFFSET; index < EXT_INTERFACE_SENSOR_CNT-1; index++) |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
629 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
630 if(pMap[index] == SENSOR_GNSS) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
631 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
632 for(index2 = 0; index2 < MAX_ADC_CHANNEL; index2++) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
633 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
634 if(pMap[index2] == SENSOR_NONE) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
635 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
636 pMap[index2] = SENSOR_GNSSM; /* store a mirror instance needed for visualization */ |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
637 Mux2ADCMap[index2] = index; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
638 break; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
639 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
640 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
641 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
642 } |
842
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
643 #ifdef ENABLE_SENTINEL_MODE |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
644 if(pMap[EXT_INTERFACE_MUX_OFFSET] == SENSOR_SENTINEL) |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
645 { |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
646 for(index2 = 0; index2 < MAX_ADC_CHANNEL; index2++) |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
647 { |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
648 pMap[index2] = SENSOR_SENTINELM; /* store a mirror instance needed for visualization */ |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
649 Mux2ADCMap[index2] = index2 + EXT_INTERFACE_MUX_OFFSET; |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
650 } |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
651 } |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
652 #endif |
804 | 653 } |
654 | |
731 | 655 uint8_t* externalInterface_GetSensorMapPointer(uint8_t finalMap) |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
656 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
657 uint8_t* pret; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
658 |
731 | 659 if((externalAutoDetect != DETECTION_OFF) && (!finalMap)) |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
660 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
661 pret = tmpSensorMap; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
662 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
663 else |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
664 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
665 pret = SensorMap; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
666 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
667 return pret; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
668 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
669 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
670 void externalInterface_AutodetectSensor() |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
671 { |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
672 static uint8_t sensorIndex = 0; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
673 static uint8_t uartMuxChannel = 0; |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
674 #ifdef ENABLE_GNSS_SUPPORT |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
675 static uint8_t detectionDelayCnt = 0; |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
676 #endif |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
677 uint8_t index = 0; |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
678 |
794 | 679 uint8_t cntSensor = 0; |
680 uint8_t cntUARTSensor = 0; | |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
681 #ifdef ENABLE_CO2_SUPPORT |
794 | 682 uint8_t cmdString[10]; |
683 uint8_t cmdLength = 0; | |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
684 #endif |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
685 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
686 if(externalAutoDetect != DETECTION_OFF) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
687 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
688 switch(externalAutoDetect) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
689 { |
804 | 690 case DETECTION_INIT: externalInterfaceMuxReqIntervall = 0; |
794 | 691 sensorIndex = 0; |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
692 uartMuxChannel = 0; |
731 | 693 tmpSensorMap[0] = SENSOR_OPTIC; |
694 tmpSensorMap[1] = SENSOR_OPTIC; | |
695 tmpSensorMap[2] = SENSOR_OPTIC; | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
696 tmpSensorMap[3] = SENSOR_NONE; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
697 tmpSensorMap[4] = SENSOR_NONE; |
804 | 698 tmpSensorMap[5] = SENSOR_NONE; |
699 tmpSensorMap[6] = SENSOR_NONE; | |
700 tmpSensorMap[7] = SENSOR_NONE; | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
701 |
794 | 702 memset(foundSensorMap, SENSOR_NONE, sizeof(foundSensorMap)); |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
703 memset(externalInterface_SensorState,UART_COMMON_INIT,sizeof(externalInterface_SensorState)); |
794 | 704 memset(Mux2ADCMap,0, sizeof(Mux2ADCMap)); |
781 | 705 |
731 | 706 if(externalInterfacePresent) |
707 { | |
708 externalInterface_SwitchPower33(0); | |
839 | 709 externalInterface_SwitchUART(EXT_INTERFACE_UART_OFF); |
731 | 710 for(index = 0; index < MAX_ADC_CHANNEL; index++) |
711 { | |
712 externalChannel_mV[index] = 0; | |
713 } | |
714 externalAutoDetect = DETECTION_START; | |
715 } | |
716 else | |
717 { | |
718 externalAutoDetect = DETECTION_DONE; /* without external interface O2 values may only be received via optical port => return default sensor map */ | |
719 } | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
720 break; |
731 | 721 case DETECTION_START: tmpSensorMap[0] = SENSOR_ANALOG; |
722 tmpSensorMap[1] = SENSOR_ANALOG; | |
723 tmpSensorMap[2] = SENSOR_ANALOG; | |
724 externalInterface_SwitchPower33(1); | |
725 externalInterface_SwitchADC(1); | |
726 externalAutoDetect = DETECTION_ANALOG1; | |
727 break; | |
728 case DETECTION_ANALOG1: externalAutoDetect = DETECTION_ANALOG2; /* do a second loop to make sure all adc channels could be processed */ | |
729 break; | |
730 case DETECTION_ANALOG2: for(index = 0; index < MAX_ADC_CHANNEL; index++) | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
731 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
732 if(externalChannel_mV[index] > MIN_ADC_VOLTAGE_MV) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
733 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
734 tmpSensorMap[sensorIndex++] = SENSOR_ANALOG; |
794 | 735 foundSensorMap[index] = SENSOR_ANALOG; |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
736 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
737 else |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
738 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
739 tmpSensorMap[sensorIndex++] = SENSOR_NONE; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
740 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
741 } |
804 | 742 externalInterfaceMuxReqIntervall = 1100; |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
743 externalAutoDetect = DETECTION_UARTMUX; |
839 | 744 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2); |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
745 externalInterface_CheckBaudrate(SENSOR_DIGO2); |
794 | 746 UART_MUX_SelectAddress(MAX_MUX_CHANNEL); |
747 uartO2_SetChannel(MAX_MUX_CHANNEL); | |
748 activeUartChannel = MAX_MUX_CHANNEL; | |
749 tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX; | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
750 break; |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
751 case DETECTION_UARTMUX: if(uartO2_isSensorConnected()) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
752 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
753 uartMuxChannel = 1; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
754 tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
755 foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
756 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
757 else |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
758 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
759 tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_NONE; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
760 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
761 externalAutoDetect = DETECTION_DIGO2_0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
762 uartO2_SetChannel(0); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
763 activeUartChannel = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
764 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET] = SENSOR_DIGO2; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
765 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET] = UART_COMMON_INIT; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
766 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
767 if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
768 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
769 UART_MUX_SelectAddress(0); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
770 } |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
771 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
772 case DETECTION_DIGO2_0: |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
773 case DETECTION_DIGO2_1: |
781 | 774 case DETECTION_DIGO2_2: |
775 case DETECTION_DIGO2_3: | |
794 | 776 if(uartO2_isSensorConnected()) |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
777 { |
794 | 778 foundSensorMap[externalAutoDetect - DETECTION_DIGO2_0 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_DIGO2; |
781 | 779 } |
804 | 780 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE; |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
781 if(uartMuxChannel) |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
782 { |
839 | 783 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2); |
794 | 784 UART_MUX_SelectAddress(uartMuxChannel); |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
785 externalInterface_SensorState[uartMuxChannel + EXT_INTERFACE_MUX_OFFSET] = UART_COMMON_INIT; |
794 | 786 uartO2_SetChannel(uartMuxChannel); |
787 activeUartChannel = uartMuxChannel; | |
788 tmpSensorMap[uartMuxChannel - 1 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE; | |
789 tmpSensorMap[uartMuxChannel + EXT_INTERFACE_MUX_OFFSET] = SENSOR_DIGO2; | |
790 | |
791 if(uartMuxChannel < MAX_MUX_CHANNEL - 1) | |
784 | 792 { |
793 uartMuxChannel++; | |
794 } | |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
795 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
796 else |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
797 { |
781 | 798 externalAutoDetect = DETECTION_DIGO2_3; /* skip detection of other serial sensors */ |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
799 } |
742 | 800 externalAutoDetect++; |
801 #ifdef ENABLE_CO2_SUPPORT | |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
802 if(externalAutoDetect == DETECTION_CO2_0) |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
803 { |
809 | 804 tmpSensorMap[uartMuxChannel + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE; |
805 if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) | |
806 { | |
807 UART_MUX_SelectAddress(0); | |
808 } | |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
809 activeUartChannel = 0; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
810 tmpSensorMap[uartMuxChannel - 1 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
811 uartMuxChannel = 1; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
812 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET] = SENSOR_CO2; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
813 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET] = UART_COMMON_INIT; |
809 | 814 externalInterface_CheckBaudrate(SENSOR_CO2); |
815 if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) /* switch sensor operation mode depending on HW config */ | |
794 | 816 { |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
817 uartCo2_SendCmd(CO2CMD_MODE_POLL, cmdString, &cmdLength); |
794 | 818 } |
819 else | |
820 { | |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
821 uartCo2_SendCmd(CO2CMD_MODE_STREAM, cmdString, &cmdLength); |
794 | 822 } |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
823 } |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
824 break; |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
825 case DETECTION_CO2_0: |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
826 case DETECTION_CO2_1: |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
827 case DETECTION_CO2_2: |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
828 case DETECTION_CO2_3: if(uartCo2_isSensorConnected()) |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
829 { |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
830 foundSensorMap[EXT_INTERFACE_MUX_OFFSET + activeUartChannel] = SENSOR_CO2; |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
831 #ifdef ENABLE_GNSS_SUPPORT |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
832 externalAutoDetect = DETECTION_GNSS_0; /* only one CO2 sensor supported */ |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
833 #else |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
834 externalAutoDetect = DETECTION_DONE; /* only one CO2 sensor supported */ |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
835 #endif |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
836 } |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
837 else if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
838 { |
809 | 839 externalInterface_CheckBaudrate(SENSOR_DIGO2); |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
840 UART_MUX_SelectAddress(uartMuxChannel); |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
841 activeUartChannel = uartMuxChannel; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
842 tmpSensorMap[uartMuxChannel - 1 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
843 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET + uartMuxChannel] = SENSOR_CO2; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
844 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET + uartMuxChannel] = UART_COMMON_INIT; |
809 | 845 externalInterface_CheckBaudrate(SENSOR_CO2); |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
846 uartCo2_SendCmd(CO2CMD_MODE_POLL, cmdString, &cmdLength); |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
847 externalAutoDetect++; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
848 uartMuxChannel++; |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
849 } |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
850 else |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
851 { |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
852 |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
853 |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
854 #if defined ENABLE_SENTINEL_MODE || defined ENABLE_GNSS_SUPPORT |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
855 #ifdef ENABLE_GNSS_SUPPORT |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
856 externalAutoDetect = DETECTION_GNSS_0; |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
857 externalInterface_SwitchUART(EXT_INTERFACE_UART_GNSS); |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
858 #else |
842
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
859 #ifdef ENABLE_SENTINEL_MODE |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
860 externalAutoDetect = DETECTION_SENTINEL; |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
861 #endif |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
862 #endif |
842
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
863 #else |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
864 externalAutoDetect = DETECTION_DONE; |
842
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
865 #endif |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
866 } |
742 | 867 #endif |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
868 |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
869 #ifdef ENABLE_GNSS_SUPPORT |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
870 if(externalAutoDetect == DETECTION_GNSS_0) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
871 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
872 tmpSensorMap[uartMuxChannel + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
873 if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
874 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
875 externalInterface_CheckBaudrate(SENSOR_DIGO2); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
876 UART_MUX_SelectAddress(0); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
877 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
878 activeUartChannel = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
879 tmpSensorMap[uartMuxChannel - 1 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
880 uartMuxChannel = 1; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
881 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET] = SENSOR_GNSS; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
882 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET] = UART_COMMON_INIT; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
883 externalInterface_CheckBaudrate(SENSOR_GNSS); |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
884 externalInterfaceMuxReqIntervall = 500; /* iterations needed for module config */ |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
885 detectionDelayCnt = 6; |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
886 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
887 break; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
888 case DETECTION_GNSS_0: |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
889 case DETECTION_GNSS_1: |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
890 case DETECTION_GNSS_2: |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
891 case DETECTION_GNSS_3: if(detectionDelayCnt == 0) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
892 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
893 if(uartGnss_isSensorConnected()) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
894 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
895 foundSensorMap[EXT_INTERFACE_MUX_OFFSET + activeUartChannel] = SENSOR_GNSS; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
896 #ifdef ENABLE_SENTINEL_MODE |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
897 externalAutoDetect = DETECTION_SENTINEL; /* only one GNSS sensor supported */ |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
898 #else |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
899 externalAutoDetect = DETECTION_DONE; /* only one GNSS sensor supported */ |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
900 #endif |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
901 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
902 else if(foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
903 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
904 externalInterface_CheckBaudrate(SENSOR_DIGO2); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
905 UART_MUX_SelectAddress(uartMuxChannel); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
906 activeUartChannel = uartMuxChannel; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
907 tmpSensorMap[uartMuxChannel - 1 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
908 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET + uartMuxChannel] = SENSOR_CO2; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
909 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET + uartMuxChannel] = UART_COMMON_INIT; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
910 externalInterface_CheckBaudrate(SENSOR_CO2); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
911 // uartGnss_SendCmd(GNSSCMD_MODE_POLL, cmdString, &cmdLength); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
912 externalAutoDetect++; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
913 detectionDelayCnt = 3; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
914 uartMuxChannel++; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
915 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
916 else |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
917 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
918 #ifdef ENABLE_SENTINEL_MODE |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
919 externalAutoDetect = DETECTION_SENTINEL; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
920 #else |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
921 externalAutoDetect = DETECTION_DONE; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
922 #endif |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
923 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
924 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
925 else |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
926 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
927 detectionDelayCnt--; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
928 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
929 #endif |
742 | 930 #ifdef ENABLE_SENTINEL_MODE |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
931 if(externalAutoDetect == DETECTION_SENTINEL) |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
932 { |
842
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
933 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET] = UART_COMMON_INIT; |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
934 uartO2_SetChannel(0); |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
935 activeUartChannel = 0; |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
936 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET] = SENSOR_SENTINEL; |
839 | 937 externalInterface_SwitchUART(EXT_INTERFACE_UART_SENTINEL); |
842
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
938 externalInterface_CheckBaudrate(SENSOR_SENTINEL); |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
939 UART_StartDMA_Receiption(); |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
940 } |
742 | 941 break; |
942 | |
943 case DETECTION_SENTINEL: | |
944 case DETECTION_SENTINEL2: | |
842
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
945 if(uartSentinel_isSensorConnected()) |
742 | 946 { |
842
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
947 for(index = EXT_INTERFACE_MUX_OFFSET; index < EXT_INTERFACE_MUX_OFFSET+3; index++) |
742 | 948 { |
842
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
949 foundSensorMap[index] = SENSOR_SENTINEL; |
742 | 950 } |
951 } | |
952 externalAutoDetect++; | |
953 #endif | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
954 break; |
794 | 955 case DETECTION_DONE: externalAutoDetect = DETECTION_OFF; |
839 | 956 externalInterface_SwitchUART(EXT_INTERFACE_UART_OFF); |
794 | 957 activeUartChannel = 0xFF; |
958 cntSensor = 0; | |
959 cntUARTSensor = 0; | |
960 for(index = 0; index < EXT_INTERFACE_SENSOR_CNT-1; index++) | |
731 | 961 { |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
962 if((foundSensorMap[index] >= SENSOR_ANALOG) && (foundSensorMap[index] < SENSOR_MUX)) |
794 | 963 { |
964 cntSensor++; | |
965 } | |
784 | 966 |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
967 if((foundSensorMap[index] == SENSOR_DIGO2) || (foundSensorMap[index] == SENSOR_CO2) || (foundSensorMap[index] == SENSOR_GNSS)) |
794 | 968 { |
969 cntUARTSensor++; | |
970 } | |
842
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
971 #ifdef ENABLE_SENTINEL_MODE |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
972 if(foundSensorMap[index] == SENSOR_SENTINEL) /* The Sentinel has a fixed setup */ |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
973 { |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
974 cntSensor = 3; |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
975 cntUARTSensor = 1; |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
976 break; |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
977 } |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
978 #endif |
786 | 979 } |
804 | 980 externalInface_MapUartToLegacyADC(foundSensorMap); |
794 | 981 externalInterfaceMuxReqIntervall = 0xFFFF; |
982 if(cntSensor == 0) /* return default sensor map if no sensor at all has been detected */ | |
784 | 983 { |
794 | 984 foundSensorMap[0] = SENSOR_OPTIC; |
985 foundSensorMap[1] = SENSOR_OPTIC; | |
986 foundSensorMap[2] = SENSOR_OPTIC; | |
987 } | |
988 else | |
989 { | |
990 if(cntUARTSensor != 0) | |
784 | 991 { |
794 | 992 externalInterfaceMuxReqIntervall = REQUEST_INT_SENSOR_MS / cntUARTSensor; |
784 | 993 } |
994 } | |
794 | 995 memcpy(SensorMap, foundSensorMap, sizeof(foundSensorMap)); |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
996 memset(externalInterface_SensorState, UART_COMMON_INIT, sizeof(externalInterface_SensorState)); |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
997 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
998 default: |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
999 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
1000 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
1001 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
1002 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
1003 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
1004 |
662 | 1005 void externalInterface_ExecuteCmd(uint16_t Cmd) |
1006 { | |
1007 char cmdString[10]; | |
1008 uint8_t cmdLength = 0; | |
804 | 1009 uint8_t index; |
794 | 1010 uint8_t cntUARTSensor = 0; |
662 | 1011 |
1012 switch(Cmd & 0x00FF) /* lower byte is reserved for commands */ | |
1013 { | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
1014 case EXT_INTERFACE_AUTODETECT: externalAutoDetect = DETECTION_INIT; |
742 | 1015 for(index = 0; index < 3; index++) |
1016 { | |
1017 SensorMap[index] = SENSOR_SEARCH; | |
1018 } | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
1019 break; |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1020 case EXT_INTERFACE_CO2_CALIB: for(index = 0; index < EXT_INTERFACE_SENSOR_CNT; index++) |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1021 { |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1022 if(SensorMap[index] == SENSOR_CO2) |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1023 { |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1024 externalInterface_SensorState[index] = UART_CO2_CALIBRATE; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1025 break; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1026 } |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1027 } |
662 | 1028 break; |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
1029 case EXT_INTERFACE_COPY_SENSORMAP: if(externalAutoDetect == DETECTION_OFF) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
1030 { |
794 | 1031 memcpy(SensorMap, MasterSensorMap, sizeof(MasterSensorMap)); |
1032 for(index = 0; index < EXT_INTERFACE_SENSOR_CNT; index++) | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
1033 { |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1034 if((SensorMap[index] == SENSOR_DIGO2) || (SensorMap[index] == SENSOR_CO2) || (SensorMap[index] == SENSOR_GNSS)) |
794 | 1035 { |
1036 cntUARTSensor++; | |
1037 } | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
1038 } |
804 | 1039 externalInface_MapUartToLegacyADC(SensorMap); |
794 | 1040 if(cntUARTSensor > 0) |
1041 { | |
1042 externalInterfaceMuxReqIntervall = REQUEST_INT_SENSOR_MS / cntUARTSensor; | |
1043 activeUartChannel = 0xFF; | |
1044 } | |
1045 else | |
1046 { | |
1047 externalInterfaceMuxReqIntervall = 0xFFFF; | |
1048 } | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
1049 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
1050 break; |
662 | 1051 default: |
1052 break; | |
1053 } | |
1054 if(cmdLength != 0) | |
1055 { | |
1056 HAL_UART_Transmit(&huart1,(uint8_t*)cmdString,cmdLength,10); | |
1057 } | |
1058 return; | |
1059 } | |
1060 | |
794 | 1061 uint8_t ExternalInterface_SelectUsedMuxChannel(uint8_t currentChannel) |
1062 { | |
1063 uint8_t index = currentChannel; | |
1064 uint8_t newChannel = index; | |
1065 uint8_t *pmap = externalInterface_GetSensorMapPointer(0); | |
1066 | |
1067 do | |
1068 { | |
1069 index++; | |
1070 if(index == MAX_MUX_CHANNEL) | |
1071 { | |
1072 index = 0; | |
1073 } | |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
1074 if(((pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_DIGO2) |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
1075 || (pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_CO2) |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
1076 || (pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_GNSS)) |
794 | 1077 && (index != activeUartChannel)) |
1078 { | |
1079 newChannel = index; | |
1080 break; | |
1081 } | |
1082 } while(index != currentChannel); | |
1083 | |
1084 return newChannel; | |
1085 } | |
1086 | |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1087 void externalInterface_CheckBaudrate(uint8_t sensorType) |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1088 { |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1089 uint32_t newBaudrate = 0; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1090 |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1091 switch(sensorType) |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1092 { |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1093 case SENSOR_GNSS: |
842
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
1094 case SENSOR_SENTINEL: |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1095 case SENSOR_CO2: newBaudrate = 9600; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1096 break; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1097 case SENSOR_DIGO2: |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1098 default: newBaudrate = 19200; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1099 break; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1100 } |
809 | 1101 if(huart1.Init.BaudRate != newBaudrate) |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1102 { |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1103 UART_ChangeBaudrate(newBaudrate); |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1104 } |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1105 } |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1106 |
794 | 1107 void externalInterface_HandleUART() |
1108 { | |
1109 static uint8_t retryRequest = 0; | |
1110 static uint32_t lastRequestTick = 0; | |
1111 static uint32_t TriggerTick = 0; | |
1112 uint8_t index = 0; | |
1113 static uint8_t timeToTrigger = 0; | |
1114 uint32_t tick = HAL_GetTick(); | |
1115 uint8_t *pmap = externalInterface_GetSensorMapPointer(0); | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1116 uint8_t forceMuxChannel = 0; |
794 | 1117 |
1118 | |
1119 if(externalInterfaceMuxReqIntervall != 0xFFFF) | |
1120 { | |
804 | 1121 if(activeUartChannel == 0xFF) |
1122 { | |
809 | 1123 MX_USART1_UART_Init(); |
804 | 1124 activeUartChannel = ExternalInterface_SelectUsedMuxChannel(0); |
1125 uartO2_SetChannel(activeUartChannel); | |
1126 | |
1127 switch(pmap[activeUartChannel + EXT_INTERFACE_MUX_OFFSET]) | |
1128 { | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1129 case SENSOR_DIGO2: |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1130 case SENSOR_GNSS: |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1131 case SENSOR_CO2: |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1132 case SENSOR_SENTINEL: externalInterface_CheckBaudrate(pmap[activeUartChannel + EXT_INTERFACE_MUX_OFFSET]); |
842
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
1133 break; |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1134 default: externalInterface_CheckBaudrate(SENSOR_DIGO2); |
804 | 1135 break; |
1136 } | |
1137 if(pmap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) | |
1138 { | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1139 HAL_Delay(10); /* make sure MUX is available for reception after wakeup */ |
804 | 1140 UART_MUX_SelectAddress(activeUartChannel); |
1141 } | |
1142 } | |
1143 | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1144 if(externalInterface_SensorState[activeSensorId] != UART_COMMON_INIT) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1145 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1146 UART_ReadData(pmap[activeSensorId]); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1147 UART_WriteData(); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1148 } |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1149 if(externalInterface_SensorState[activeSensorId] == UART_COMMON_INIT) |
794 | 1150 { |
1151 lastRequestTick = tick; | |
1152 TriggerTick = tick - 10; /* just to make sure control is triggered */ | |
1153 timeToTrigger = 1; | |
1154 retryRequest = 0; | |
1155 } | |
1156 else if(((retryRequest == 0) /* timeout or error */ | |
1157 && (((time_elapsed_ms(lastRequestTick,tick) > (TIMEOUT_SENSOR_ANSWER)) && (externalInterface_SensorState[activeSensorId] != UART_O2_IDLE)) /* retry if no answer after half request interval */ | |
1158 || (externalInterface_SensorState[activeSensorId] == UART_O2_ERROR)))) | |
1159 { | |
1160 /* The channel switch will cause the sensor to respond with an error message. */ | |
1161 /* The sensor needs ~30ms to recover before he is ready to receive the next command => transmission delay needed */ | |
1162 | |
1163 TriggerTick = tick; | |
1164 timeToTrigger = COMMAND_TX_DELAY; | |
1165 retryRequest = 1; | |
1166 } | |
1167 | |
1168 else if(time_elapsed_ms(lastRequestTick,tick) > externalInterfaceMuxReqIntervall) /* switch sensor and / or trigger next request */ | |
1169 { | |
1170 lastRequestTick = tick; | |
1171 TriggerTick = tick; | |
1172 retryRequest = 0; | |
1173 timeToTrigger = 1; | |
1174 | |
1175 if((externalInterface_SensorState[activeSensorId] == UART_O2_REQ_O2) /* timeout */ | |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1176 || (externalInterface_SensorState[activeSensorId] == UART_O2_REQ_RAW) |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
1177 || (externalInterface_SensorState[activeSensorId] == UART_CO2_OPERATING) |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
1178 || (externalInterface_SensorState[activeSensorId] == UART_GNSS_GET_PVT)) |
794 | 1179 { |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1180 forceMuxChannel = 1; |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
1181 externalInterface_SensorState[activeSensorId] = UART_O2_IDLE; |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1182 switch(pmap[activeSensorId]) |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1183 { |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1184 case SENSOR_DIGO2: setExternalInterfaceChannel(activeSensorId,0.0); |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1185 break; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1186 case SENSOR_CO2: externalInterface_SetCO2Value(0.0); |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1187 externalInterface_SetCO2State(0); |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1188 break; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1189 default: |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1190 break; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1191 } |
794 | 1192 } |
1193 | |
1194 if(pmap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) /* select next sensor if mux is connected */ | |
1195 { | |
1196 if(activeUartChannel < MAX_MUX_CHANNEL) | |
1197 { | |
1198 index = ExternalInterface_SelectUsedMuxChannel(activeUartChannel); | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1199 if((index != activeUartChannel) || (forceMuxChannel)) |
794 | 1200 { |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1201 forceMuxChannel = 0; |
794 | 1202 timeToTrigger = 100; |
1203 activeUartChannel = index; | |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1204 if((pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_DIGO2) |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1205 || (pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_CO2) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1206 || (pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_GNSS)) |
794 | 1207 { |
1208 uartO2_SetChannel(activeUartChannel); | |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1209 externalInterface_CheckBaudrate(SENSOR_MUX); |
794 | 1210 UART_MUX_SelectAddress(activeUartChannel); |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1211 externalInterface_CheckBaudrate(pmap[activeUartChannel + EXT_INTERFACE_MUX_OFFSET]); |
794 | 1212 } |
1213 } | |
1214 } | |
1215 } | |
1216 else | |
1217 { | |
1218 timeToTrigger = 1; | |
1219 } | |
1220 } | |
1221 if((timeToTrigger != 0) && (time_elapsed_ms(TriggerTick,tick) > timeToTrigger)) | |
1222 { | |
1223 timeToTrigger = 0; | |
1224 switch (pmap[activeSensorId]) | |
1225 { | |
1226 case SENSOR_MUX: | |
1227 case SENSOR_DIGO2: uartO2_Control(); | |
1228 break; | |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1229 #ifdef ENABLE_CO2_SUPPORT |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1230 case SENSOR_CO2: uartCo2_Control(); |
794 | 1231 break; |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
1232 #endif |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1233 #ifdef ENABLE_GNSS_SUPPORT |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1234 case SENSOR_GNSS: uartGnss_Control(); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1235 break; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
861
diff
changeset
|
1236 #endif |
842
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
1237 #ifdef ENABLE_SENTINEL_MODE |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
1238 case SENSOR_SENTINEL: uartSentinel_Control(); |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
1239 break; |
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
839
diff
changeset
|
1240 #endif |
794 | 1241 default: |
1242 break; | |
1243 } | |
1244 } | |
921 | 1245 #if 0 |
1246 else | |
1247 { | |
1248 if(((time_elapsed_ms(lastRequestTick,tick) > (externalInterfaceMuxReqIntervall - 100)) | |
1249 && externalInterface_SensorState[activeSensorId] = UART_COMMON_IDLE)) | |
1250 { | |
1251 externalInterface_ReadAndSwitch(); | |
1252 } | |
1253 } | |
1254 #endif | |
794 | 1255 } |
1256 | |
1257 #if 0 | |
1258 #ifdef ENABLE_SENTINEL_MODE | |
839 | 1259 if(externalInterface_GetUARTProtocol() & (EXT_INTERFACE_UART_SENTINEL)) |
794 | 1260 { |
1261 UART_HandleSentinelData(); | |
1262 } | |
1263 #endif | |
1264 #endif | |
1265 } |