Mercurial > public > ostc4
annotate Small_CPU/Src/externalInterface.c @ 796:75ace7af8212
Expanded Sensor map structure:
In the previous version the number of possible sensors were set to 5 based on the assumption that ADC slots are shared with digital O2 sensors. As result three of five slots would have been limited to O2 measurement usecase, leaving just two slots left for other sensors (e.g. CO2). In order to have as much flexibility (and less risk for data structure changes) the number of sensors has been set to 7 (3 ADC + 4 UART MUX)
author | Ideenmodellierer |
---|---|
date | Mon, 31 Jul 2023 20:00:06 +0200 |
parents | bb37d4f3e50e |
children | e9eba334b942 |
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" |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
36 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
37 extern SGlobal global; |
662 | 38 extern UART_HandleTypeDef huart1; |
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 #define ADC_ANSWER_LENGTH (5u) /* 3424 will provide addr + 4 data bytes */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
41 #define ADC_TIMEOUT (10u) /* conversion stuck for unknown reason => restart */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
42 #define ADC_REF_VOLTAGE_MV (2048.0f) /* reference voltage of MPC3424*/ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
43 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
44 #define ADC_START_CONVERSION (0x80) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
45 #define ADC_GAIN_4 (0x02) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
46 #define ADC_GAIN_4_VALUE (4.0f) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
47 #define ADC_GAIN_8 (0x03) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
48 #define ADC_GAIN_8_VALUE (8.0f) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
49 #define ADC_RESOLUTION_16BIT (0x08) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
50 #define ADC_RESOLUTION_16BIT_VALUE (16u) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
51 #define ADC_RESOLUTION_18BIT (0x0C) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
52 #define ADC_RESOLUTION_18BIT_VALUE (18u) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
53 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
54 #define ANSWER_CONFBYTE_INDEX (4u) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
55 |
747
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
56 #define LOOKUP_CO2_CORR_TABLE_SCALE (1000u) |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
57 #define LOOKUP_CO2_CORR_TABLE_MAX (30000u) |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
58 |
794 | 59 #define REQUEST_INT_SENSOR_MS (1500) /* Minimum time interval for cyclic sensor data requests per sensor (UART mux) */ |
60 #define COMMAND_TX_DELAY (30u) /* The time the sensor needs to recover from a invalid command request */ | |
61 #define TIMEOUT_SENSOR_ANSWER (300) /* Time till a request is repeated if no answer was received */ | |
62 | |
63 #define activeSensorId (activeUartChannel + EXT_INTERFACE_MUX_OFFSET) /* Used if UART channels are applied to Sensor map */ | |
64 | |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
65 static uint8_t activeChannel = 0; /* channel which is in request */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
66 static uint8_t recBuf[ADC_ANSWER_LENGTH]; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
67 static uint8_t timeoutCnt = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
68 static uint8_t externalInterfacePresent = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
69 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
70 float externalChannel_mV[MAX_ADC_CHANNEL]; |
662 | 71 static uint8_t externalV33_On = 0; |
691 | 72 static uint8_t externalADC_On = 0; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
73 static uint8_t externalUART_Protocol = 0; |
662 | 74 static uint16_t externalCO2Value; |
75 static uint16_t externalCO2SignalStrength; | |
794 | 76 static uint16_t externalCO2Status = 0; |
77 static float externalCO2Scale = 0.0; | |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
78 |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
79 static uint8_t lastSensorDataId = 0; |
794 | 80 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
|
81 static externalInterfaceAutoDetect_t externalAutoDetect = DETECTION_OFF; |
747
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
82 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
|
83 static externalInterfaceSensorType tmpSensorMap[EXT_INTERFACE_SENSOR_CNT]; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
84 static externalInterfaceSensorType MasterSensorMap[EXT_INTERFACE_SENSOR_CNT]; |
794 | 85 static externalInterfaceSensorType foundSensorMap[EXT_INTERFACE_SENSOR_CNT]; |
86 static uint8_t Mux2ADCMap[MAX_ADC_CHANNEL]; | |
87 static uint8_t externalInterface_SensorState[EXT_INTERFACE_SENSOR_CNT]; | |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
88 |
747
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
89 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
|
90 |
794 | 91 static uint16_t externalInterfaceMuxReqIntervall = 0; /* delay between switching from one MUX channel to the next */ |
92 static uint8_t activeUartChannel = 0; /* Index of the sensor port which is selected by the mux or 0 if no mux is connected */ | |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
93 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
94 void externalInterface_Init(void) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
95 { |
747
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
96 uint16_t index; |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
97 uint16_t coeff; |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
98 activeChannel = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
99 timeoutCnt = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
100 externalInterfacePresent = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
101 if(externalInterface_StartConversion(activeChannel) == HAL_OK) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
102 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
103 externalInterfacePresent = 1; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
104 global.deviceDataSendToMaster.hw_Info.extADC = 1; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
105 } |
559 | 106 global.deviceDataSendToMaster.hw_Info.checkADC = 1; |
662 | 107 |
794 | 108 memset(Mux2ADCMap,0xFF, sizeof(Mux2ADCMap)); |
109 | |
747
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
110 /* 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
|
111 /* The main purpose of the sensor in the dive application is to be a warning indicator */ |
753 | 112 /* => 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
|
113 LookupCO2PressureCorrection [0] = -0.0014; |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
114 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
|
115 { |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
116 coeff = index * LOOKUP_CO2_CORR_TABLE_SCALE; |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
117 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
|
118 } |
738
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
119 externalInterface_InitDatastruct(); |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
120 } |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
121 |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
122 void externalInterface_InitDatastruct(void) |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
123 { |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
124 uint8_t index = 0; |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
125 /* init data values */ |
662 | 126 externalV33_On = 0; |
127 externalCO2Value = 0; | |
128 externalCO2SignalStrength = 0; | |
129 externalCO2Status = 0; | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
130 externalAutoDetect = DETECTION_OFF; |
738
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 for(index = 0; index < MAX_ADC_CHANNEL; index++) |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
133 { |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
134 externalChannel_mV[index] = 0.0; |
30717de00f3a
Added data init function for external interface:
Ideenmodellierer
parents:
731
diff
changeset
|
135 } |
794 | 136 memset(externalInterface_SensorState,UART_O2_INIT,sizeof(externalInterface_SensorState)); |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
137 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
138 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
139 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
140 uint8_t externalInterface_StartConversion(uint8_t channel) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
141 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
142 uint8_t retval = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
143 uint8_t confByte = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
144 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
145 if(channel < MAX_ADC_CHANNEL) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
146 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
147 confByte = ADC_START_CONVERSION | ADC_RESOLUTION_16BIT | ADC_GAIN_8; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
148 confByte |= channel << 5; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
149 retval = I2C_Master_Transmit(DEVICE_EXTERNAL_ADC, &confByte, 1); |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
150 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
151 return retval; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
152 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
153 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
154 /* Check if conversion is done and trigger measurement of next channel */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
155 uint8_t externalInterface_ReadAndSwitch() |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
156 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
157 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
|
158 uint8_t nextChannel; |
731 | 159 uint8_t* psensorMap = externalInterface_GetSensorMapPointer(0); |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
160 |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
161 if(externalADC_On) |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
162 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
163 if(I2C_Master_Receive(DEVICE_EXTERNAL_ADC, recBuf, ADC_ANSWER_LENGTH) == HAL_OK) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
164 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
165 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
|
166 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
167 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
|
168 nextChannel = activeChannel + 1; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
169 if(nextChannel == MAX_ADC_CHANNEL) |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
170 { |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
171 nextChannel = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
172 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
173 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
174 while((psensorMap[nextChannel] != SENSOR_ANALOG) && (nextChannel != activeChannel)) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
175 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
176 if(nextChannel == MAX_ADC_CHANNEL) |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
177 { |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
178 nextChannel = 0; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
179 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
180 else |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
181 { |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
182 nextChannel++; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
183 } |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
184 } |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
185 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
186 activeChannel = nextChannel; |
554
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
187 externalInterface_StartConversion(activeChannel); |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
188 timeoutCnt = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
189 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
190 else |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
191 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
192 if(timeoutCnt++ >= ADC_TIMEOUT) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
193 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
194 externalInterface_StartConversion(activeChannel); |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
195 timeoutCnt = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
196 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
197 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
198 } |
581
011d8f9f5ddb
Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents:
559
diff
changeset
|
199 else /* take also i2c bus disturb into account */ |
011d8f9f5ddb
Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents:
559
diff
changeset
|
200 { |
011d8f9f5ddb
Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents:
559
diff
changeset
|
201 if(timeoutCnt++ >= ADC_TIMEOUT) |
011d8f9f5ddb
Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents:
559
diff
changeset
|
202 { |
011d8f9f5ddb
Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents:
559
diff
changeset
|
203 externalInterface_StartConversion(activeChannel); |
011d8f9f5ddb
Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents:
559
diff
changeset
|
204 timeoutCnt = 0; |
011d8f9f5ddb
Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents:
559
diff
changeset
|
205 } |
011d8f9f5ddb
Added ex Interface measurement restart in case of i2c disturbance:
Ideenmodellierer
parents:
559
diff
changeset
|
206 } |
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 return retval; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
209 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
210 float externalInterface_CalculateADCValue(uint8_t channel) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
211 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
212 int32_t rawvalue = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
213 float retValue = 0.0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
214 if(channel < MAX_ADC_CHANNEL) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
215 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
216 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
217 rawvalue = ((recBuf[0] << 16) | (recBuf[1] << 8) | (recBuf[2])); |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
218 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
219 switch(recBuf[3] & 0x0C) /* confbyte => Resolution bits*/ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
220 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
221 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
|
222 if(rawvalue & (0x1 << (ADC_RESOLUTION_16BIT_VALUE-1))) /* MSB set => negative number */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
223 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
224 rawvalue |= 0xFFFF0000; /* set MSB for int32 */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
225 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
226 else |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
227 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
228 rawvalue &= 0x0000FFFF; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
229 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
230 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
|
231 break; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
232 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
|
233 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
234 rawvalue |= 0xFFFE0000; /* set MSB for int32 */ |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
235 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
236 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
|
237 break; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
238 default: rawvalue = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
239 break; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
240 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
241 externalChannel_mV[channel] = externalChannel_mV[channel] * rawvalue / ADC_GAIN_8_VALUE; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
242 retValue = externalChannel_mV[channel]; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
243 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
244 return retValue; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
245 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
246 float getExternalInterfaceChannel(uint8_t channel) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
247 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
248 float retval = 0; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
249 |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
250 if(channel < MAX_ADC_CHANNEL) |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
251 { |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
252 retval = externalChannel_mV[channel]; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
253 } |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
254 return retval; |
3328189786e7
Added external ADC interface functionality (MCP3424):
Ideenmodellierer
parents:
diff
changeset
|
255 } |
662 | 256 |
691 | 257 uint8_t setExternalInterfaceChannel(uint8_t channel, float value) |
258 { | |
259 uint8_t retval = 0; | |
794 | 260 uint8_t localId = channel; |
261 uint8_t index = 0; | |
691 | 262 |
794 | 263 if(localId >= MAX_ADC_CHANNEL) /* at the moment sensor visualization is focused on the three ADC channels => map Mux sensors */ |
691 | 264 { |
794 | 265 for(index = 0; index < MAX_ADC_CHANNEL; index++) |
266 { | |
267 if(Mux2ADCMap[index] == localId) | |
268 { | |
269 localId = index; | |
270 break; | |
271 } | |
272 } | |
273 } | |
274 | |
275 if(localId < MAX_ADC_CHANNEL) | |
276 { | |
277 externalChannel_mV[localId] = value; | |
691 | 278 retval = 1; |
279 } | |
280 return retval; | |
281 } | |
282 | |
662 | 283 void externalInterface_InitPower33(void) |
284 { | |
285 GPIO_InitTypeDef GPIO_InitStructure; | |
286 | |
287 GPIO_InitStructure.Pin = GPIO_PIN_7; | |
288 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
289 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
290 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | |
291 HAL_GPIO_Init(GPIOC, &GPIO_InitStructure); | |
292 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET); | |
293 } | |
294 | |
295 | |
296 uint8_t externalInterface_isEnabledPower33() | |
297 { | |
298 return externalV33_On; | |
299 } | |
691 | 300 |
301 uint8_t externalInterface_isEnabledADC() | |
302 { | |
303 return externalADC_On; | |
304 } | |
305 | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
306 uint8_t externalInterface_GetUARTProtocol() |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
307 { |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
308 return externalUART_Protocol; |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
309 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
310 |
662 | 311 void externalInterface_SwitchPower33(uint8_t state) |
312 { | |
313 if(state != externalV33_On) | |
314 { | |
315 if(state) | |
316 { | |
317 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_RESET); | |
318 externalV33_On = 1; | |
319 } | |
320 else | |
321 { | |
731 | 322 if(externalAutoDetect == DETECTION_OFF) |
323 { | |
324 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET); | |
325 externalV33_On = 0; | |
326 externalInterface_SetCO2Value(0); | |
327 externalInterface_SetCO2SignalStrength(0); | |
328 } | |
662 | 329 } |
330 } | |
331 } | |
691 | 332 void externalInterface_SwitchADC(uint8_t state) |
333 { | |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
334 uint8_t loop = 0; |
691 | 335 if((state) && (externalInterfacePresent)) |
336 { | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
337 if(externalADC_On == 0) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
338 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
339 activeChannel = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
340 externalInterface_StartConversion(activeChannel); |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
341 externalADC_On = 1; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
342 } |
691 | 343 } |
344 else | |
345 { | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
346 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
|
347 { |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
348 externalADC_On = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
349 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
|
350 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
351 externalChannel_mV[loop] = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
352 } |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
353 } |
691 | 354 } |
355 } | |
662 | 356 |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
357 void externalInterface_SwitchUART(uint8_t protocol) |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
358 { |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
359 switch(protocol) |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
360 { |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
361 case 0: |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
362 case (EXT_INTERFACE_UART_CO2 >> 8): |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
363 case (EXT_INTERFACE_UART_O2 >> 8): |
742 | 364 case (EXT_INTERFACE_UART_SENTINEL >> 8): |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
365 if((externalAutoDetect <= DETECTION_START) |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
366 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2_0)) |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
367 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2_1)) |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
368 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2_2)) |
781 | 369 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2_3)) |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
370 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_UARTMUX)) |
746 | 371 #ifdef ENABLE_CO2_SUPPORT |
372 || ((protocol == EXT_INTERFACE_UART_CO2 >> 8) && (externalAutoDetect == DETECTION_CO2)) | |
373 #endif | |
374 #ifdef ENABLE_SENTINEL_MODE | |
375 || ((protocol == EXT_INTERFACE_UART_SENTINEL >> 8) && (externalAutoDetect == DETECTION_SENTINEL)) | |
376 #endif | |
377 ) | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
378 { |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
379 lastSensorDataId = 0; |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
380 externalUART_Protocol = protocol; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
381 MX_USART1_UART_DeInit(); |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
382 if( protocol != 0) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
383 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
384 MX_USART1_UART_Init(); |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
385 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
386 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
387 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
388 default: |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
389 break; |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
390 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
391 } |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
691
diff
changeset
|
392 |
794 | 393 uint8_t externalInterface_GetActiveUartSensor() |
394 { | |
395 return activeUartChannel; | |
396 } | |
397 | |
398 void externalInterface_SetSensorState(uint8_t sensorIdx, uint8_t state) | |
399 { | |
400 if(sensorIdx < EXT_INTERFACE_SENSOR_CNT) | |
401 { | |
402 externalInterface_SensorState[sensorIdx] = state; | |
403 } | |
404 } | |
405 | |
406 uint8_t externalInterface_GetSensorState(uint8_t sensorIdx) | |
407 { | |
408 uint8_t ret = COMMON_SENSOR_STATE_INVALID; | |
409 if(sensorIdx < EXT_INTERFACE_SENSOR_CNT) | |
410 { | |
411 ret = externalInterface_SensorState[sensorIdx]; | |
412 } | |
413 return ret; | |
414 } | |
415 | |
416 /* The supported sensors from GSS have different scaling factors depending on their accuracy. The factor may be read out of the sensor */ | |
417 void externalInterface_SetCO2Scale(float CO2Scale) | |
418 { | |
419 if((CO2Scale == 10) || (CO2Scale == 100)) | |
420 { | |
421 externalCO2Scale = CO2Scale; | |
422 } | |
423 } | |
424 float externalInterface_GetCO2Scale() | |
425 { | |
426 return externalCO2Scale; | |
427 } | |
428 | |
662 | 429 void externalInterface_SetCO2Value(uint16_t CO2_ppm) |
430 { | |
794 | 431 float local_ppm = CO2_ppm * externalCO2Scale; |
747
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
432 |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
433 #ifndef ENABLE_EXTERNAL_PRESSURE |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
434 float local_corr = 0.0; |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
435 |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
436 if (local_ppm >= LOOKUP_CO2_CORR_TABLE_MAX) |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
437 { |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
438 local_corr = -0.0014; |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
439 } |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
440 else |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
441 { |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
442 local_corr = LookupCO2PressureCorrection[((uint16_t) (local_ppm / LOOKUP_CO2_CORR_TABLE_SCALE))]; |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
443 } |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
444 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
|
445 #else |
df0d43da1614
Added pressure compensation to CO2 detection:
Ideenmodellierer
parents:
746
diff
changeset
|
446 /* 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
|
447 /* 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
|
448 #endif |
794 | 449 externalCO2Value = local_ppm / externalCO2Scale; |
662 | 450 } |
451 | |
452 void externalInterface_SetCO2SignalStrength(uint16_t LED_qa) | |
453 { | |
454 externalCO2SignalStrength = LED_qa; | |
455 } | |
456 | |
457 uint16_t externalInterface_GetCO2Value(void) | |
458 { | |
459 return externalCO2Value; | |
460 } | |
461 | |
462 uint16_t externalInterface_GetCO2SignalStrength(void) | |
463 { | |
464 return externalCO2SignalStrength; | |
465 } | |
466 | |
467 | |
468 void externalInterface_SetCO2State(uint16_t state) | |
469 { | |
470 externalCO2Status = state; | |
471 } | |
472 | |
473 uint16_t externalInterface_GetCO2State(void) | |
474 { | |
475 return externalCO2Status; | |
476 } | |
477 | |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
478 |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
479 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
|
480 { |
794 | 481 uint8_t index = 0; |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
482 uint8_t localId = sensorId; |
786 | 483 if(localId == 0xFF) |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
484 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
485 localId = lastSensorDataId; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
486 } |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
487 |
794 | 488 if((pDataStruct != NULL) && (localId <= EXT_INTERFACE_SENSOR_CNT)) |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
489 { |
786 | 490 memcpy(pDataStruct, &sensorDataDiveO2[localId], sizeof(SSensorDataDiveO2)); |
491 } | |
492 else | |
493 { | |
494 localId = 0xFF; | |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
495 } |
794 | 496 if(localId > MAX_ADC_CHANNEL) /* at the moment sensor visualization is focused on the three ADC channels => map Mux sensors */ |
497 { | |
498 for(index = 0; index < MAX_ADC_CHANNEL; index++) | |
499 { | |
500 if(Mux2ADCMap[index] == localId) | |
501 { | |
502 localId = index; | |
503 } | |
504 } | |
505 } | |
506 | |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
507 return localId; |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
508 } |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
509 |
786 | 510 void externalInterface_SetSensorData(uint8_t sensorId, uint8_t* pDataStruct) |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
511 { |
794 | 512 uint8_t index = 0; |
513 | |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
514 if(pDataStruct != NULL) |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
515 { |
794 | 516 if((sensorId != 0xFF) && (sensorId < EXT_INTERFACE_SENSOR_CNT)) |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
517 { |
786 | 518 memcpy(&sensorDataDiveO2[sensorId], pDataStruct, sizeof(SSensorDataDiveO2)); |
519 lastSensorDataId = sensorId; | |
794 | 520 for(index = 0; index < MAX_MUX_CHANNEL; index++) |
521 { | |
522 if(Mux2ADCMap[index] == sensorId) | |
523 { | |
524 memcpy(&sensorDataDiveO2[index], pDataStruct, sizeof(SSensorDataDiveO2)); | |
525 lastSensorDataId = index; | |
526 break; | |
527 } | |
528 } | |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
529 } |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
530 else |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
531 { |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
532 memset(&sensorDataDiveO2,0,sizeof(sensorDataDiveO2)); |
786 | 533 lastSensorDataId = 0xFF; |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
534 } |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
535 } |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
536 } |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
704
diff
changeset
|
537 |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
538 void externalInface_SetSensorMap(uint8_t* pMap) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
539 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
540 if(pMap != NULL) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
541 { |
794 | 542 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
|
543 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
544 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
545 } |
731 | 546 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
|
547 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
548 uint8_t* pret; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
549 |
731 | 550 if((externalAutoDetect != DETECTION_OFF) && (!finalMap)) |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
551 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
552 pret = tmpSensorMap; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
553 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
554 else |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
555 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
556 pret = SensorMap; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
557 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
558 return pret; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
559 } |
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 void externalInterface_AutodetectSensor() |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
562 { |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
563 static uint8_t sensorIndex = 0; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
564 static uint8_t uartMuxChannel = 0; |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
565 uint8_t index = 0; |
794 | 566 uint8_t index2 = 0; |
567 uint8_t cntSensor = 0; | |
568 uint8_t cntUARTSensor = 0; | |
569 uint8_t cmdString[10]; | |
570 uint8_t cmdLength = 0; | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
571 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
572 if(externalAutoDetect != DETECTION_OFF) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
573 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
574 switch(externalAutoDetect) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
575 { |
794 | 576 case DETECTION_INIT: externalInterfaceMuxReqIntervall = 1100; |
577 sensorIndex = 0; | |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
578 uartMuxChannel = 0; |
731 | 579 tmpSensorMap[0] = SENSOR_OPTIC; |
580 tmpSensorMap[1] = SENSOR_OPTIC; | |
581 tmpSensorMap[2] = SENSOR_OPTIC; | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
582 tmpSensorMap[3] = SENSOR_NONE; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
583 tmpSensorMap[4] = SENSOR_NONE; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
584 |
794 | 585 memset(foundSensorMap, SENSOR_NONE, sizeof(foundSensorMap)); |
586 memset(externalInterface_SensorState,UART_O2_INIT,sizeof(externalInterface_SensorState)); | |
587 memset(Mux2ADCMap,0, sizeof(Mux2ADCMap)); | |
781 | 588 |
731 | 589 if(externalInterfacePresent) |
590 { | |
591 externalInterface_SwitchPower33(0); | |
592 externalInterface_SwitchUART(0); | |
593 for(index = 0; index < MAX_ADC_CHANNEL; index++) | |
594 { | |
595 externalChannel_mV[index] = 0; | |
596 } | |
597 externalAutoDetect = DETECTION_START; | |
598 } | |
599 else | |
600 { | |
601 externalAutoDetect = DETECTION_DONE; /* without external interface O2 values may only be received via optical port => return default sensor map */ | |
602 } | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
603 break; |
731 | 604 case DETECTION_START: tmpSensorMap[0] = SENSOR_ANALOG; |
605 tmpSensorMap[1] = SENSOR_ANALOG; | |
606 tmpSensorMap[2] = SENSOR_ANALOG; | |
607 externalInterface_SwitchPower33(1); | |
608 externalInterface_SwitchADC(1); | |
609 externalAutoDetect = DETECTION_ANALOG1; | |
610 break; | |
611 case DETECTION_ANALOG1: externalAutoDetect = DETECTION_ANALOG2; /* do a second loop to make sure all adc channels could be processed */ | |
612 break; | |
613 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
|
614 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
615 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
|
616 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
617 tmpSensorMap[sensorIndex++] = SENSOR_ANALOG; |
794 | 618 foundSensorMap[index] = SENSOR_ANALOG; |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
619 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
620 else |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
621 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
622 tmpSensorMap[sensorIndex++] = SENSOR_NONE; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
623 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
624 } |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
625 externalAutoDetect = DETECTION_UARTMUX; |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
626 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2 >> 8); |
794 | 627 UART_MUX_SelectAddress(MAX_MUX_CHANNEL); |
628 uartO2_SetChannel(MAX_MUX_CHANNEL); | |
629 activeUartChannel = MAX_MUX_CHANNEL; | |
630 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
|
631 break; |
794 | 632 case DETECTION_UARTMUX: if(uartO2_isSensorConnected()) |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
633 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
634 uartMuxChannel = 1; |
794 | 635 tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX; |
636 foundSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX; | |
637 } | |
638 else | |
639 { | |
640 tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_NONE; | |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
641 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
642 externalAutoDetect = DETECTION_DIGO2_0; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
643 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2 >> 8); |
794 | 644 UART_MUX_SelectAddress(0); |
645 uartO2_SetChannel(0); | |
646 activeUartChannel = 0; | |
647 tmpSensorMap[EXT_INTERFACE_MUX_OFFSET] = SENSOR_DIGO2; | |
648 externalInterface_SensorState[EXT_INTERFACE_MUX_OFFSET] = UART_O2_INIT; | |
649 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2 >> 8); | |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
650 break; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
651 case DETECTION_DIGO2_0: |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
652 case DETECTION_DIGO2_1: |
781 | 653 case DETECTION_DIGO2_2: |
654 case DETECTION_DIGO2_3: | |
794 | 655 if(uartO2_isSensorConnected()) |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
656 { |
794 | 657 foundSensorMap[externalAutoDetect - DETECTION_DIGO2_0 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_DIGO2; |
781 | 658 } |
794 | 659 |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
660 if(uartMuxChannel) |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
661 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
662 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2 >> 8); |
794 | 663 UART_MUX_SelectAddress(uartMuxChannel); |
664 externalInterface_SensorState[uartMuxChannel + EXT_INTERFACE_MUX_OFFSET] = UART_O2_INIT; | |
665 uartO2_SetChannel(uartMuxChannel); | |
666 activeUartChannel = uartMuxChannel; | |
667 tmpSensorMap[uartMuxChannel - 1 + EXT_INTERFACE_MUX_OFFSET] = SENSOR_NONE; | |
668 tmpSensorMap[uartMuxChannel + EXT_INTERFACE_MUX_OFFSET] = SENSOR_DIGO2; | |
669 | |
670 if(uartMuxChannel < MAX_MUX_CHANNEL - 1) | |
784 | 671 { |
672 uartMuxChannel++; | |
673 } | |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
674 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
675 else |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
676 { |
781 | 677 externalAutoDetect = DETECTION_DIGO2_3; /* skip detection of other serial sensors */ |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
678 } |
742 | 679 externalAutoDetect++; |
680 #ifdef ENABLE_CO2_SUPPORT | |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
681 if(externalAutoDetect == DETECTION_CO2) |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
682 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
683 externalInterface_SwitchUART(EXT_INTERFACE_UART_CO2 >> 8); |
794 | 684 if(tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) /* switch sensor operation mode depending on HW config */ |
685 { | |
686 DigitalCO2_SendCmd(CO2CMD_MODE_POLL, cmdString, &cmdLength); | |
687 } | |
688 else | |
689 { | |
690 DigitalCO2_SendCmd(CO2CMD_MODE_STREAM, cmdString, &cmdLength); | |
691 } | |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
692 } |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
693 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
694 case DETECTION_CO2: if(UART_isCO2Connected()) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
695 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
696 for(index = 0; index < 3; index++) /* lookup a channel which may be used by CO2*/ |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
697 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
698 if(tmpSensorMap[index] == SENSOR_NONE) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
699 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
700 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
701 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
702 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
703 if(index == 3) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
704 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
705 tmpSensorMap[sensorIndex++] = SENSOR_CO2; /* place Co2 sensor behind O2 sensors (not visible) */ |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
706 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
707 else |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
708 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
709 tmpSensorMap[index] = SENSOR_CO2; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
710 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
711 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
712 } |
742 | 713 externalAutoDetect++; |
714 #endif | |
715 #ifdef ENABLE_SENTINEL_MODE | |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
716 if(externalAutoDetect == DETECTION_SENTINEL) |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
717 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
718 externalInterface_SwitchUART(EXT_INTERFACE_UART_SENTINEL >> 8); |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
719 UART_StartDMA_Receiption(); |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
753
diff
changeset
|
720 } |
742 | 721 break; |
722 | |
723 case DETECTION_SENTINEL: | |
724 case DETECTION_SENTINEL2: | |
725 if(UART_isSentinelConnected()) | |
726 { | |
727 for(index = 0; index < 3; index++) /* Sentinel is occupiing all sensor slots */ | |
728 { | |
729 tmpSensorMap[index] = SENSOR_SENTINEL; | |
730 } | |
731 sensorIndex = 3; | |
732 } | |
733 externalAutoDetect++; | |
734 #endif | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
735 break; |
794 | 736 case DETECTION_DONE: externalAutoDetect = DETECTION_OFF; |
737 externalInterface_SwitchUART(0); | |
738 activeUartChannel = 0xFF; | |
739 cntSensor = 0; | |
740 cntUARTSensor = 0; | |
741 for(index = 0; index < EXT_INTERFACE_SENSOR_CNT-1; index++) | |
731 | 742 { |
794 | 743 if((foundSensorMap[index] >= SENSOR_ANALOG) && (foundSensorMap[index] < SENSOR_TYPE_O2_END)) |
744 { | |
745 cntSensor++; | |
746 } | |
784 | 747 |
794 | 748 if((foundSensorMap[index] == SENSOR_DIGO2) || (foundSensorMap[index] == SENSOR_CO2)) |
749 { | |
750 cntUARTSensor++; | |
751 } | |
786 | 752 |
794 | 753 /* Map Mux O2 sensors to ADC Slot if ADC slot is not in use */ |
754 if(foundSensorMap[index] == SENSOR_DIGO2) | |
786 | 755 { |
794 | 756 for(index2 = 0; index2 < MAX_ADC_CHANNEL; index2++) |
757 { | |
758 if(foundSensorMap[index2] == SENSOR_NONE) | |
759 { | |
760 foundSensorMap[index2] = SENSOR_DIGO2M; /* store a mirror instance needed for visualization */ | |
761 Mux2ADCMap[index2] = index; | |
762 break; | |
763 } | |
764 } | |
786 | 765 } |
766 } | |
794 | 767 externalInterfaceMuxReqIntervall = 0xFFFF; |
768 if(cntSensor == 0) /* return default sensor map if no sensor at all has been detected */ | |
784 | 769 { |
794 | 770 foundSensorMap[0] = SENSOR_OPTIC; |
771 foundSensorMap[1] = SENSOR_OPTIC; | |
772 foundSensorMap[2] = SENSOR_OPTIC; | |
773 } | |
774 else | |
775 { | |
776 if(cntUARTSensor != 0) | |
784 | 777 { |
794 | 778 externalInterfaceMuxReqIntervall = REQUEST_INT_SENSOR_MS / cntUARTSensor; |
784 | 779 } |
780 } | |
794 | 781 memcpy(SensorMap, foundSensorMap, sizeof(foundSensorMap)); |
782 memset(externalInterface_SensorState,UART_O2_INIT,sizeof(externalInterface_SensorState)); | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
783 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
784 default: |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
785 break; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
786 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
787 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
788 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
789 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
790 |
662 | 791 void externalInterface_ExecuteCmd(uint16_t Cmd) |
792 { | |
793 char cmdString[10]; | |
794 uint8_t cmdLength = 0; | |
794 | 795 uint8_t index, index2; |
796 uint8_t cntUARTSensor = 0; | |
797 uint8_t lastMappedID = 0; | |
798 | |
662 | 799 |
800 switch(Cmd & 0x00FF) /* lower byte is reserved for commands */ | |
801 { | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
802 case EXT_INTERFACE_AUTODETECT: externalAutoDetect = DETECTION_INIT; |
742 | 803 for(index = 0; index < 3; index++) |
804 { | |
805 SensorMap[index] = SENSOR_SEARCH; | |
806 } | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
807 break; |
662 | 808 case EXT_INTERFACE_CO2_CALIB: cmdLength = snprintf(cmdString, 10, "G\r\n"); |
809 break; | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
810 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
|
811 { |
794 | 812 memcpy(SensorMap, MasterSensorMap, sizeof(MasterSensorMap)); |
813 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
|
814 { |
794 | 815 if((SensorMap[index] == SENSOR_DIGO2) || (SensorMap[index] == SENSOR_CO2)) |
816 { | |
817 cntUARTSensor++; | |
818 } | |
819 if(SensorMap[index] == SENSOR_DIGO2M) /* find matching sensor for mirror */ | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
820 { |
794 | 821 for(index2 = EXT_INTERFACE_MUX_OFFSET; index2 < EXT_INTERFACE_SENSOR_CNT; index2++) |
822 { | |
823 if(SensorMap[index2] == SENSOR_DIGO2) | |
824 { | |
825 if(lastMappedID < index2) | |
826 { | |
827 lastMappedID = index2; | |
828 Mux2ADCMap[index] = index2; | |
829 break; | |
830 } | |
831 } | |
832 } | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
833 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
834 } |
794 | 835 if(cntUARTSensor > 0) |
836 { | |
837 externalInterfaceMuxReqIntervall = REQUEST_INT_SENSOR_MS / cntUARTSensor; | |
838 activeUartChannel = 0xFF; | |
839 } | |
840 else | |
841 { | |
842 externalInterfaceMuxReqIntervall = 0xFFFF; | |
843 } | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
844 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
714
diff
changeset
|
845 break; |
662 | 846 default: |
847 break; | |
848 } | |
849 if(cmdLength != 0) | |
850 { | |
851 HAL_UART_Transmit(&huart1,(uint8_t*)cmdString,cmdLength,10); | |
852 } | |
853 return; | |
854 } | |
855 | |
794 | 856 uint8_t ExternalInterface_SelectUsedMuxChannel(uint8_t currentChannel) |
857 { | |
858 uint8_t index = currentChannel; | |
859 uint8_t newChannel = index; | |
860 uint8_t *pmap = externalInterface_GetSensorMapPointer(0); | |
861 | |
862 do | |
863 { | |
864 index++; | |
865 if(index == MAX_MUX_CHANNEL) | |
866 { | |
867 index = 0; | |
868 } | |
869 if(((pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_DIGO2) || (pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_CO2)) | |
870 && (index != activeUartChannel)) | |
871 { | |
872 newChannel = index; | |
873 break; | |
874 } | |
875 } while(index != currentChannel); | |
876 | |
877 return newChannel; | |
878 } | |
879 | |
880 void externalInterface_HandleUART() | |
881 { | |
882 static uint8_t retryRequest = 0; | |
883 static uint32_t lastRequestTick = 0; | |
884 static uint32_t TriggerTick = 0; | |
885 uint8_t index = 0; | |
886 static uint8_t timeToTrigger = 0; | |
887 uint32_t tick = HAL_GetTick(); | |
888 uint8_t *pmap = externalInterface_GetSensorMapPointer(0); | |
889 | |
890 | |
891 UART_ReadData(pmap[activeSensorId]); | |
892 | |
893 if(activeUartChannel == 0xFF) | |
894 { | |
895 activeUartChannel = ExternalInterface_SelectUsedMuxChannel(0); | |
896 uartO2_SetChannel(activeUartChannel); | |
897 if(pmap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) | |
898 { | |
899 UART_MUX_SelectAddress(activeUartChannel); | |
900 } | |
901 UART_FlushRxBuffer(); | |
902 } | |
903 | |
904 if(externalInterfaceMuxReqIntervall != 0xFFFF) | |
905 { | |
906 if(externalInterface_SensorState[activeSensorId] == UART_O2_INIT) | |
907 { | |
908 lastRequestTick = tick; | |
909 TriggerTick = tick - 10; /* just to make sure control is triggered */ | |
910 timeToTrigger = 1; | |
911 retryRequest = 0; | |
912 } | |
913 else if(((retryRequest == 0) /* timeout or error */ | |
914 && (((time_elapsed_ms(lastRequestTick,tick) > (TIMEOUT_SENSOR_ANSWER)) && (externalInterface_SensorState[activeSensorId] != UART_O2_IDLE)) /* retry if no answer after half request interval */ | |
915 || (externalInterface_SensorState[activeSensorId] == UART_O2_ERROR)))) | |
916 { | |
917 /* The channel switch will cause the sensor to respond with an error message. */ | |
918 /* The sensor needs ~30ms to recover before he is ready to receive the next command => transmission delay needed */ | |
919 | |
920 TriggerTick = tick; | |
921 timeToTrigger = COMMAND_TX_DELAY; | |
922 retryRequest = 1; | |
923 } | |
924 | |
925 else if(time_elapsed_ms(lastRequestTick,tick) > externalInterfaceMuxReqIntervall) /* switch sensor and / or trigger next request */ | |
926 { | |
927 lastRequestTick = tick; | |
928 TriggerTick = tick; | |
929 retryRequest = 0; | |
930 timeToTrigger = 1; | |
931 | |
932 if((externalInterface_SensorState[activeSensorId] == UART_O2_REQ_O2) /* timeout */ | |
933 || (externalInterface_SensorState[activeSensorId] == UART_O2_REQ_RAW)) | |
934 { | |
935 setExternalInterfaceChannel(activeSensorId,0.0); | |
936 } | |
937 | |
938 if(pmap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) /* select next sensor if mux is connected */ | |
939 { | |
940 if(activeUartChannel < MAX_MUX_CHANNEL) | |
941 { | |
942 index = ExternalInterface_SelectUsedMuxChannel(activeUartChannel); | |
943 if(index != activeUartChannel) | |
944 { | |
945 timeToTrigger = 100; | |
946 activeUartChannel = index; | |
947 if(pmap[index + EXT_INTERFACE_MUX_OFFSET] == SENSOR_DIGO2) | |
948 { | |
949 uartO2_SetChannel(activeUartChannel); | |
950 UART_MUX_SelectAddress(activeUartChannel); | |
951 } | |
952 } | |
953 } | |
954 } | |
955 else | |
956 { | |
957 timeToTrigger = 1; | |
958 } | |
959 } | |
960 if((timeToTrigger != 0) && (time_elapsed_ms(TriggerTick,tick) > timeToTrigger)) | |
961 { | |
962 timeToTrigger = 0; | |
963 switch (pmap[activeSensorId]) | |
964 { | |
965 case SENSOR_MUX: | |
966 case SENSOR_DIGO2: uartO2_Control(); | |
967 break; | |
968 // case SENSOR_CO2: uartCO2_Control(); | |
969 break; | |
970 default: | |
971 break; | |
972 } | |
973 } | |
974 } | |
975 | |
976 | |
977 | |
978 #if 0 | |
979 #ifdef ENABLE_CO2_SUPPORT | |
980 if(externalInterface_GetUARTProtocol() & (EXT_INTERFACE_UART_CO2 >> 8)) | |
981 { | |
982 UART_HandleCO2Data(); | |
983 } | |
984 #endif | |
985 #ifdef ENABLE_SENTINEL_MODE | |
986 if(externalInterface_GetUARTProtocol() & (EXT_INTERFACE_UART_SENTINEL >> 8)) | |
987 { | |
988 UART_HandleSentinelData(); | |
989 } | |
990 #endif | |
991 if(externalInterface_GetUARTProtocol() & (EXT_INTERFACE_UART_O2 >> 8)) | |
992 { | |
993 UART_HandleDigitalO2(); | |
994 } | |
995 #endif | |
996 | |
997 | |
998 } |