# HG changeset patch # User Ideenmodellierer # Date 1659705988 -7200 # Node ID 52d68cf9994c87076ba5ba75ba59aaf609308a1d # Parent fca2bd25e6e201a3596742e6d4ca0dd01e73f396 Improvment external interface usage: The previous implementation of the external interface was straight forward for ADC and Co2 UART usage. The new implementation provides the possibility to configurate the behavior of the external interface. e.g. Switching of external3,3V and ADC separatly and selection of UART protocol. diff -r fca2bd25e6e2 -r 52d68cf9994c Common/Inc/data_exchange.h --- a/Common/Inc/data_exchange.h Fri Aug 05 15:22:26 2022 +0200 +++ b/Common/Inc/data_exchange.h Fri Aug 05 15:26:28 2022 +0200 @@ -31,9 +31,20 @@ #include "settings.h" #include "stm32f4xx_hal.h" -/* Command definitions for contral of external interface */ -#define EXT_INTERFACE_33V_ON (0x8000u) /* Bit set to enable 3.3V power interface */ -#define EXT_INTERFACE_CO2_CALIB (0x0001u) /* Request calibration of CO2Sensor */ +/* Command definitions for control of external interface */ +/* 1st nibble binary on/off states */ +/* 2nd nibble UART protocol selection */ +/* 3rd nibble reserve */ +/* 4th nibble command channel */ +#define EXT_INTERFACE_33V_ON (0x8000u) /* Bit set to enable 3.3V power interface */ +#define EXT_INTERFACE_ADC_ON (0x4000u) /* Bit set to enable ADC conversion */ +#define EXT_INTERFACE_UART_MASK (0x0700u) /* Reserve 3 bits for UART protocol selection */ +#define EXT_INTERFACE_UART_CO2 (0x0100u) /* Activate protocol for CO2 sensor */ +#define EXT_INTERFACE_UART_SENTINEL (0x0200u) /* Activate Sentinel Backup monitor protocol */ +#define EXT_INTERFACE_CO2_CALIB (0x0001u) /* Request calibration of CO2Sensor */ + +#define DATA_BUFFER_ADC (0x01u) +#define DATA_BUFFER_CO2 (0x02u) enum MODE { @@ -216,7 +227,7 @@ uint8_t chargeStatus; uint8_t boolPICdata; confirmbit8_Type confirmRequest; // confirmbit8_Type - uint8_t boolWirelessData; + uint8_t boolADCO2Data; uint8_t boolPressureData; uint8_t boolCompassData; diff -r fca2bd25e6e2 -r 52d68cf9994c Common/Inc/settings.h --- a/Common/Inc/settings.h Fri Aug 05 15:22:26 2022 +0200 +++ b/Common/Inc/settings.h Fri Aug 05 15:26:28 2022 +0200 @@ -36,6 +36,8 @@ // From Common/Drivers/ #include "stm32f4xx_hal.h" +#include "configuration.h" + #include @@ -80,12 +82,17 @@ #define PSCR_MIN_LUNG_RATIO (5u) #define PSCR_MAX_LUNG_RATIO (20u) -#define FUTURE_SPARE_SIZE (29u) /* Applied for reuse of old, not used, scooter block (was 32 bytes)*/ +#define UART_MAX_PROTOCOL (2u) + +#define FUTURE_SPARE_SIZE (28u) /* Applied for reuse of old, not used, scooter block (was 32 bytes)*/ typedef enum { O2_SENSOR_SOURCE_OPTIC = 0, O2_SENSOR_SOURCE_ANALOG, +#ifdef ENABLE_SENTINEL_MODE + O2_SENSOR_SOURCE_SENTINEL, +#endif O2_SENSOR_SOURCE_MAX } SensorSource; #define MAX_O2_SENSOR_SOURCE (2u) @@ -213,6 +220,7 @@ uint8_t pscr_lung_ratio; /* redefined in 0xFFFF0020 */ uint8_t pscr_o2_drop; /* redefined in 0xFFFF0020 */ uint8_t co2_sensor_active; /* redefined in 0xFFFF0021 */ + uint8_t ext_uart_protocol; /* redefined in 0xFFFF0022 */ uint8_t Future_SPARE[FUTURE_SPARE_SIZE]; /* redefined in 0xFFFF0020 (old scooter Block was 32 byte)*/ // new in 0xFFFF0006 uint8_t ppo2sensors_deactivated; diff -r fca2bd25e6e2 -r 52d68cf9994c Discovery/Src/data_exchange_main.c --- a/Discovery/Src/data_exchange_main.c Fri Aug 05 15:22:26 2022 +0200 +++ b/Discovery/Src/data_exchange_main.c Fri Aug 05 15:26:28 2022 +0200 @@ -391,9 +391,28 @@ dataOut.data.offsetPressureSensor_mbar = settings->offsetPressure_mbar; dataOut.data.offsetTemperatureSensor_centiDegree = settings->offsetTemperature_centigrad; + + + if(settings->ppo2sensors_source == O2_SENSOR_SOURCE_ANALOG) + { + externalInterface_Cmd |= EXT_INTERFACE_ADC_ON | EXT_INTERFACE_33V_ON; + } + +#ifdef ENABLE_SENTINEL_MODE + if(settings->ppo2sensors_source == O2_SENSOR_SOURCE_SENTINEL) + { + externalInterface_Cmd |= EXT_INTERFACE_33V_ON | EXT_INTERFACE_UART_SENTINEL; + externalInterface_Cmd &= (~EXT_INTERFACE_ADC_ON); + } +#endif + + if(settings->ext_uart_protocol) + { + externalInterface_Cmd |= (settings->ext_uart_protocol << 8); + } if(settings->co2_sensor_active) { - externalInterface_Cmd |= EXT_INTERFACE_33V_ON; + externalInterface_Cmd |= EXT_INTERFACE_33V_ON | EXT_INTERFACE_UART_CO2; } dataOut.data.externalInterface_Cmd = externalInterface_Cmd; externalInterface_Cmd = 0; @@ -920,7 +939,7 @@ { for(idx = 0; idx < 3; idx++) { - pStateReal->lifeData.sensorVoltage_mV[idx] = dataIn.data[0].extADC_voltage[idx]; + pStateReal->lifeData.sensorVoltage_mV[idx] = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_ADC)].extADC_voltage[idx]; if(pStateReal->lifeData.sensorVoltage_mV[idx] < IGNORE_O2_VOLTAGE_LEVEL_MV) { pStateReal->lifeData.sensorVoltage_mV[idx] = 0.0; @@ -1082,8 +1101,8 @@ pStateReal->sensorErrorsRTE = dataIn.sensorErrors; /* data from CO2 sensor */ - pStateReal->lifeData.CO2_data.CO2_ppm = dataIn.data[0].CO2_ppm; - pStateReal->lifeData.CO2_data.signalStrength = dataIn.data[0].CO2_signalStrength; + pStateReal->lifeData.CO2_data.CO2_ppm = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_CO2)].CO2_ppm; + pStateReal->lifeData.CO2_data.signalStrength = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_CO2)].CO2_signalStrength; } /* apnea specials diff -r fca2bd25e6e2 -r 52d68cf9994c Small_CPU/Inc/externalInterface.h --- a/Small_CPU/Inc/externalInterface.h Fri Aug 05 15:22:26 2022 +0200 +++ b/Small_CPU/Inc/externalInterface.h Fri Aug 05 15:26:28 2022 +0200 @@ -40,8 +40,11 @@ uint8_t externalInterface_ReadAndSwitch(); float externalInterface_CalculateADCValue(uint8_t channel); float getExternalInterfaceChannel(uint8_t channel); +uint8_t setExternalInterfaceChannel(uint8_t channel, float value); void externalInterface_SwitchPower33(uint8_t state); -uint8_t externalInterface_isEnabledPower33(); +void externalInterface_SwitchADC(uint8_t state); +uint8_t externalInterface_isEnabledPower33(void); +uint8_t externalInterface_isEnabledADC(void); void externalInterface_SetCO2Value(uint16_t CO2_ppm); void externalInterface_SetCO2SignalStrength(uint16_t LED_qa); diff -r fca2bd25e6e2 -r 52d68cf9994c Small_CPU/Src/externalInterface.c --- a/Small_CPU/Src/externalInterface.c Fri Aug 05 15:22:26 2022 +0200 +++ b/Small_CPU/Src/externalInterface.c Fri Aug 05 15:26:28 2022 +0200 @@ -56,6 +56,7 @@ float externalChannel_mV[MAX_ADC_CHANNEL]; static uint8_t externalV33_On = 0; +static uint8_t externalADC_On = 0; static uint16_t externalCO2Value; static uint16_t externalCO2SignalStrength; static uint16_t externalCO2Status = 0; @@ -182,6 +183,18 @@ return retval; } +uint8_t setExternalInterfaceChannel(uint8_t channel, float value) +{ + uint8_t retval = 0; + + if(channel < MAX_ADC_CHANNEL) + { + externalChannel_mV[channel] = value; + retval = 1; + } + return retval; +} + void externalInterface_InitPower33(void) { GPIO_InitTypeDef GPIO_InitStructure; @@ -199,6 +212,12 @@ { return externalV33_On; } + +uint8_t externalInterface_isEnabledADC() +{ + return externalADC_On; +} + void externalInterface_SwitchPower33(uint8_t state) { if(state != externalV33_On) @@ -219,6 +238,18 @@ } } } +void externalInterface_SwitchADC(uint8_t state) +{ + if((state) && (externalInterfacePresent)) + { + externalInterface_StartConversion(activeChannel); + externalADC_On = 1; + } + else + { + externalADC_On = 0; + } +} void externalInterface_SetCO2Value(uint16_t CO2_ppm) { diff -r fca2bd25e6e2 -r 52d68cf9994c Small_CPU/Src/scheduler.c --- a/Small_CPU/Src/scheduler.c Fri Aug 05 15:22:26 2022 +0200 +++ b/Small_CPU/Src/scheduler.c Fri Aug 05 15:26:28 2022 +0200 @@ -313,7 +313,13 @@ externalInterface_SwitchPower33(global.dataSendToSlave.data.externalInterface_Cmd && EXT_INTERFACE_33V_ON); } - if(global.dataSendToSlave.data.externalInterface_Cmd > EXT_INTERFACE_33V_ON) + if(((global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_ADC_ON) != 0) != externalInterface_isEnabledADC()) + { + externalInterface_SwitchADC(global.dataSendToSlave.data.externalInterface_Cmd && EXT_INTERFACE_ADC_ON); + } + + + if(global.dataSendToSlave.data.externalInterface_Cmd & 0x00FF) /* lowest nibble for commands */ { externalInterface_ExecuteCmd(global.dataSendToSlave.data.externalInterface_Cmd); } @@ -505,6 +511,20 @@ lasttick = HAL_GetTick(); ticksdiff = time_elapsed_ms(Scheduler.tickstart,lasttick); +#ifdef ENABLE_CO2_SUPPORT + if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_SENTINEL) + { + HandleUARTCO2Data(); + } +#endif +#ifdef ENABLE_SENTINEL_MODE + if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_SENTINEL) + { + HandleUARTSentinelData(); + } +#endif + + if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) { if(SPI_Evaluate_RX_Data()!=0) /* did we receive something ? */ @@ -513,12 +533,15 @@ } schedule_check_resync(); - extAdcChannel = externalInterface_ReadAndSwitch(); - if(extAdcChannel != EXTERNAL_ADC_NO_DATA) + if(externalInterface_isEnabledADC()) { - externalInterface_CalculateADCValue(extAdcChannel); - copyExtADCdata(); + extAdcChannel = externalInterface_ReadAndSwitch(); + if(extAdcChannel != EXTERNAL_ADC_NO_DATA) + { + externalInterface_CalculateADCValue(extAdcChannel); + } } + copyExtADCdata(); copyExtCO2data(); } @@ -806,8 +829,19 @@ if(scheduleSetButtonResponsiveness()) setButtonsNow = 0; } - - HandleUARTData(); + +#ifdef ENABLE_CO2_SUPPORT + if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_SENTINEL) + { + HandleUARTCO2Data(); + } +#endif +#ifdef ENABLE_SENTINEL_MODE + if(global.dataSendToSlave.data.externalInterface_Cmd & EXT_INTERFACE_UART_SENTINEL) + { + HandleUARTSentinelData(); + } +#endif /* Evaluate received data at 10 ms, 110 ms, 210 ms,... duration ~<1ms */ if(ticksdiff >= Scheduler.counterSPIdata100msec * 100 + 10) @@ -817,12 +851,16 @@ Scheduler.counterSPIdata100msec++; } schedule_check_resync(); - extAdcChannel = externalInterface_ReadAndSwitch(); - if(extAdcChannel != EXTERNAL_ADC_NO_DATA) + if(externalInterface_isEnabledADC()) { - externalInterface_CalculateADCValue(extAdcChannel); - copyExtADCdata(); + extAdcChannel = externalInterface_ReadAndSwitch(); + if(extAdcChannel != EXTERNAL_ADC_NO_DATA) + { + externalInterface_CalculateADCValue(extAdcChannel); + + } } + copyExtADCdata(); copyExtCO2data(); } @@ -926,6 +964,7 @@ copyBatteryData(); copyDeviceData(); + /* check if I2C is not up an running and try to reactivate if necessary. Also do initialization if problem occured during startup */ if(global.I2C_SystemStatus != HAL_OK) { @@ -1109,12 +1148,12 @@ } } - if(secondsCount >= 30) + if((secondsCount >= 30) || (global.mode != MODE_SLEEP)) /* Service battery charge state in case sleep is left */ { pressure_sensor_get_temperature_raw(); battery_gas_gauge_get_data(); ReInit_battery_charger_status_pins(); - battery_charger_get_status_and_contral_battery_gas_gauge(30); + battery_charger_get_status_and_contral_battery_gas_gauge(secondsCount); // DeInit_battery_charger_status_pins(); secondsCount = 0; } @@ -1672,32 +1711,43 @@ uint8_t channel = 0; + uint8_t boolADCBuffer = ~(global.dataSendToMaster.boolADCO2Data & DATA_BUFFER_ADC); + + boolADCBuffer &= DATA_BUFFER_ADC; + global.dataSendToMaster.boolADCO2Data &= ~DATA_BUFFER_ADC; + for(channel = 0; channel < MAX_ADC_CHANNEL; channel++) { value = getExternalInterfaceChannel(channel); - global.dataSendToMaster.data[0].extADC_voltage[channel] = value; + global.dataSendToMaster.data[boolADCBuffer && DATA_BUFFER_ADC].extADC_voltage[channel] = value; } + global.dataSendToMaster.boolADCO2Data |= boolADCBuffer; } void copyExtCO2data() { uint16_t value; + uint8_t boolCO2Buffer = ~(global.dataSendToMaster.boolADCO2Data & DATA_BUFFER_CO2); + + global.dataSendToMaster.boolADCO2Data &= ~DATA_BUFFER_CO2; + boolCO2Buffer &= DATA_BUFFER_CO2; if(externalInterface_GetCO2State()) { value = externalInterface_GetCO2Value(); - global.dataSendToMaster.data[0].CO2_ppm = value; + global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].CO2_ppm = value; value = externalInterface_GetCO2SignalStrength(); - global.dataSendToMaster.data[0].CO2_signalStrength = value; - global.dataSendToMaster.data[0].externalInterface_CmdAnswer = externalInterface_GetCO2State(); + global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].CO2_signalStrength = value; + global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].externalInterface_CmdAnswer = externalInterface_GetCO2State(); externalInterface_SetCO2State(EXT_INTERFACE_33V_ON); /* clear command responses */ } else { - global.dataSendToMaster.data[0].CO2_ppm = 0; - global.dataSendToMaster.data[0].CO2_signalStrength = 0; - global.dataSendToMaster.data[0].externalInterface_CmdAnswer = 0; + global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].CO2_ppm = 0; + global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].CO2_signalStrength = 0; + global.dataSendToMaster.data[(boolCO2Buffer && DATA_BUFFER_CO2)].externalInterface_CmdAnswer = 0; } + global.dataSendToMaster.boolADCO2Data |= boolCO2Buffer; } typedef enum