Mercurial > public > ostc4
changeset 731:2a801cfe23ab
Improvment sensor Autodetection:
The sensor type optical has been introduce to enable the OSTC to completly switch of the external interface (voltage + ADC operation) The optical interface is handled via firmware. In addition some states have been added to reset the external power supply and to provide the ADC more time to do its conversation.
author | Ideenmodellierer |
---|---|
date | Sun, 15 Jan 2023 21:43:33 +0100 |
parents | 9c65d226f4f6 |
children | e33d661d1743 |
files | Small_CPU/Inc/externalInterface.h Small_CPU/Src/externalInterface.c Small_CPU/Src/scheduler.c Small_CPU/Src/uart.c |
diffstat | 4 files changed, 64 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/Small_CPU/Inc/externalInterface.h Sat Jan 14 20:49:40 2023 +0100 +++ b/Small_CPU/Inc/externalInterface.h Sun Jan 15 21:43:33 2023 +0100 @@ -41,7 +41,9 @@ { DETECTION_OFF = 0, /* no detection requested */ DETECTION_INIT, /* prepare external interface for operation if not already activated */ - DETECTION_ANALOG, /* check ADC channels for connected sensors */ + DETECTION_START, + DETECTION_ANALOG1, /* check ADC channels for connected sensors */ + DETECTION_ANALOG2, DETECTION_DIGO2, /* check UART channel for connected DigO2 sensor */ DETECTION_CO2, /* check UART channel for connected CO2 sensor */ DETECTION_DONE @@ -73,7 +75,7 @@ uint8_t externalInterface_GetSensorData(uint8_t* pDataStruct); void externalInterface_SetSensorData(uint8_t dataId, uint8_t* pDataStruct); void externalInface_SetSensorMap(uint8_t* pMap); -uint8_t* externalInterface_GetSensorMapPointer(void); +uint8_t* externalInterface_GetSensorMapPointer(uint8_t finalMap); void externalInterface_AutodetectSensor(void); void externalInterface_ExecuteCmd(uint16_t Cmd);
--- a/Small_CPU/Src/externalInterface.c Sat Jan 14 20:49:40 2023 +0100 +++ b/Small_CPU/Src/externalInterface.c Sun Jan 15 21:43:33 2023 +0100 @@ -111,7 +111,7 @@ { uint8_t retval = EXTERNAL_ADC_NO_DATA; uint8_t nextChannel; - uint8_t* psensorMap = externalInterface_GetSensorMapPointer(); + uint8_t* psensorMap = externalInterface_GetSensorMapPointer(0); if(externalADC_On) { @@ -260,10 +260,13 @@ } else { - HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET); - externalV33_On = 0; - externalInterface_SetCO2Value(0); - externalInterface_SetCO2SignalStrength(0); + if(externalAutoDetect == DETECTION_OFF) + { + HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET); + externalV33_On = 0; + externalInterface_SetCO2Value(0); + externalInterface_SetCO2SignalStrength(0); + } } } } @@ -299,8 +302,8 @@ case 0: case (EXT_INTERFACE_UART_CO2 >> 8): case (EXT_INTERFACE_UART_O2 >> 8): - if((externalAutoDetect == DETECTION_OFF) || ((protocol == EXT_INTERFACE_UART_CO2 >> 8) && (externalAutoDetect == DETECTION_CO2)) - || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2))) + if((externalAutoDetect <= DETECTION_START) || ((protocol == EXT_INTERFACE_UART_CO2 >> 8) && (externalAutoDetect == DETECTION_CO2)) + || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2))) { sensorDataId = 0; externalUART_Protocol = protocol; @@ -382,11 +385,11 @@ } } -uint8_t* externalInterface_GetSensorMapPointer() +uint8_t* externalInterface_GetSensorMapPointer(uint8_t finalMap) { uint8_t* pret; - if(externalAutoDetect != DETECTION_OFF) + if((externalAutoDetect != DETECTION_OFF) && (!finalMap)) { pret = tmpSensorMap; } @@ -407,16 +410,37 @@ switch(externalAutoDetect) { case DETECTION_INIT: sensorIndex = 0; - tmpSensorMap[0] = SENSOR_ANALOG; - tmpSensorMap[1] = SENSOR_ANALOG; - tmpSensorMap[2] = SENSOR_ANALOG; + tmpSensorMap[0] = SENSOR_OPTIC; + tmpSensorMap[1] = SENSOR_OPTIC; + tmpSensorMap[2] = SENSOR_OPTIC; tmpSensorMap[3] = SENSOR_NONE; tmpSensorMap[4] = SENSOR_NONE; - externalInterface_SwitchADC(1); - externalAutoDetect = DETECTION_ANALOG; + if(externalInterfacePresent) + { + externalInterface_SwitchPower33(0); + externalInterface_SwitchUART(0); + for(index = 0; index < MAX_ADC_CHANNEL; index++) + { + externalChannel_mV[index] = 0; + } + externalAutoDetect = DETECTION_START; + } + else + { + externalAutoDetect = DETECTION_DONE; /* without external interface O2 values may only be received via optical port => return default sensor map */ + } break; - case DETECTION_ANALOG: for(index = 0; index < MAX_ADC_CHANNEL; index++) + case DETECTION_START: tmpSensorMap[0] = SENSOR_ANALOG; + tmpSensorMap[1] = SENSOR_ANALOG; + tmpSensorMap[2] = SENSOR_ANALOG; + externalInterface_SwitchPower33(1); + externalInterface_SwitchADC(1); + externalAutoDetect = DETECTION_ANALOG1; + break; + case DETECTION_ANALOG1: externalAutoDetect = DETECTION_ANALOG2; /* do a second loop to make sure all adc channels could be processed */ + break; + case DETECTION_ANALOG2: for(index = 0; index < MAX_ADC_CHANNEL; index++) { if(externalChannel_mV[index] > MIN_ADC_VOLTAGE_MV) { @@ -475,9 +499,26 @@ } externalAutoDetect = DETECTION_DONE; break; - case DETECTION_DONE: while(sensorIndex < 5) + case DETECTION_DONE: for(index = 0; index < EXT_INTERFACE_SENSOR_CNT; index++) + { + if(tmpSensorMap[index] != SENSOR_NONE) + { + break; + } + } + + if(index != EXT_INTERFACE_SENSOR_CNT) /* return default sensor map if no sensor at all has been detected */ { - tmpSensorMap[sensorIndex++] = SENSOR_NONE; + while(sensorIndex < EXT_INTERFACE_SENSOR_CNT) + { + tmpSensorMap[sensorIndex++] = SENSOR_NONE; + } + } + else + { + tmpSensorMap[0] = SENSOR_OPTIC; + tmpSensorMap[1] = SENSOR_OPTIC; + tmpSensorMap[2] = SENSOR_OPTIC; } memcpy(SensorMap, tmpSensorMap, sizeof(tmpSensorMap)); externalAutoDetect = DETECTION_OFF;
--- a/Small_CPU/Src/scheduler.c Sat Jan 14 20:49:40 2023 +0100 +++ b/Small_CPU/Src/scheduler.c Sun Jan 15 21:43:33 2023 +0100 @@ -1736,7 +1736,7 @@ global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].extADC_voltage[channel] = value; } global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].externalInterface_SensorID = externalInterface_GetSensorData((uint8_t*)&global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].sensor_data); - memcpy(global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].sensor_map,externalInterface_GetSensorMapPointer(),EXT_INTERFACE_SENSOR_CNT); + memcpy(global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].sensor_map,externalInterface_GetSensorMapPointer(1),EXT_INTERFACE_SENSOR_CNT); global.dataSendToMaster.boolADCO2Data |= boolADCBuffer; }