Mercurial > public > ostc4
diff Small_CPU/Src/externalInterface.c @ 781:01b3eb9d55c3
Update real multiplexer implementation:
The final multiplexer provides 4 sensor connections instead of three supported by the prototype => A mupping functionality has been introduced to map the 4 possible mux addresses to the three visible O2 sensor slots.
In addition the request cycle time is not depending on the number of sensors connected to make sure that all sensors are read within a defined time frame.
The error reaction had to be updated to reset mux channels if one of the sensors fails to respond.
author | Ideenmodellierer |
---|---|
date | Mon, 29 May 2023 18:26:55 +0200 |
parents | 0b5f45448eb6 |
children | 95af969fe0ae |
line wrap: on
line diff
--- a/Small_CPU/Src/externalInterface.c Tue May 23 21:50:19 2023 +0200 +++ b/Small_CPU/Src/externalInterface.c Mon May 29 18:26:55 2023 +0200 @@ -335,6 +335,7 @@ || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2_0)) || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2_1)) || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2_2)) + || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2_3)) || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_UARTMUX)) #ifdef ENABLE_CO2_SUPPORT || ((protocol == EXT_INTERFACE_UART_CO2 >> 8) && (externalAutoDetect == DETECTION_CO2)) @@ -464,10 +465,11 @@ void externalInterface_AutodetectSensor() { - static uint8_t tmpMuxMapping[MAX_ADC_CHANNEL]; + static uint8_t tmpMuxMapping[MAX_MUX_CHANNEL]; static uint8_t sensorIndex = 0; static uint8_t uartMuxChannel = 0; uint8_t index = 0; + uint8_t index2 = 0; if(externalAutoDetect != DETECTION_OFF) { @@ -486,6 +488,8 @@ UART_MapDigO2_Channel(index,index); /* request all addresses */ tmpMuxMapping[index] = 0xff; } + UART_MapDigO2_Channel(3,4); + if(externalInterfacePresent) { externalInterface_SwitchPower33(0); @@ -523,7 +527,7 @@ } externalAutoDetect = DETECTION_UARTMUX; externalInterface_SwitchUART(EXT_INTERFACE_UART_O2 >> 8); - UART_SetDigO2_Channel(3); + UART_SetDigO2_Channel(MAX_MUX_CHANNEL); break; case DETECTION_UARTMUX: if(UART_isDigO2Connected()) { @@ -536,7 +540,9 @@ break; case DETECTION_DIGO2_0: case DETECTION_DIGO2_1: - case DETECTION_DIGO2_2: if(UART_isDigO2Connected()) + case DETECTION_DIGO2_2: + case DETECTION_DIGO2_3: + if(UART_isDigO2Connected()) { for(index = 0; index < 3; index++) /* lookup a channel which may be used by digO2 */ { @@ -552,11 +558,12 @@ else { tmpSensorMap[index] = SENSOR_DIGO2; - tmpMuxMapping[index] = externalAutoDetect - DETECTION_DIGO2_0; + tmpMuxMapping[externalAutoDetect - DETECTION_DIGO2_0] = index; } - UART_setTargetChannel(index); - - /* tmpSensorMap[sensorIndex++] = SENSOR_DIGO2; */ + } + else + { + UART_MapDigO2_Channel(0xff, externalAutoDetect - DETECTION_DIGO2_0); } if(uartMuxChannel) { @@ -566,7 +573,7 @@ } else { - externalAutoDetect = DETECTION_DIGO2_2; /* skip detection of other serial sensors */ + externalAutoDetect = DETECTION_DIGO2_3; /* skip detection of other serial sensors */ } externalAutoDetect++; #ifdef ENABLE_CO2_SUPPORT @@ -621,9 +628,14 @@ { tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX; } - for(index = 0; index < MAX_ADC_CHANNEL; index++) + index2 = 0; /* used for target channel */ + for(index = 0; index < MAX_MUX_CHANNEL; index++) { - UART_MapDigO2_Channel(index,tmpMuxMapping[index]); + if(tmpMuxMapping[index] != 0xff) + { + UART_MapDigO2_Channel(index2, index); + index2++; + } } externalAutoDetect = DETECTION_OFF; externalInterface_SwitchUART(0); @@ -664,7 +676,6 @@ break; } } - UART_setTargetChannel(index); /* if no slot for digO2 is found then the function will be called with an invalid parameter causing the overwrite function to fail */ } break; default: