Mercurial > public > ostc4
diff Small_CPU/Src/scheduler.c @ 691:52d68cf9994c Betatest
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.
author | Ideenmodellierer |
---|---|
date | Fri, 05 Aug 2022 15:26:28 +0200 |
parents | 079bb5b22c06 |
children | f1b40364b0af |
line wrap: on
line diff
--- 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