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