# HG changeset patch # User Ideenmodellierer # Date 1738167680 -3600 # Node ID 0b81ac558e89c3d949ca2c791d03210324668341 # Parent 142f3d0363b34a5d6047652ebd35c455aa175df4 Devbugfix UART buffer cleaning: In the previous version a buffer cleaning function was used which resets the ringbuffer read index. As result the processing of data was stopped until the DMA write comes to the index 0. When reaching it the complete buffer was proceeded including possibly invalid data. The usage of the cleanbuffer function was replaced by the flush buffer function (meaning the data is discarded but the data index is maintained). There was already a function for this. Because the function was 99% the same as the read function, it was integrated into the ReadData function. Calling the function with parameter flush = 1 will result in a buffer flush. The workaround of the previous revision was updated to only be applied in case a DiveO2 sensor is operated in stand alone mode. diff -r 142f3d0363b3 -r 0b81ac558e89 Small_CPU/Inc/uart.h --- a/Small_CPU/Inc/uart.h Tue Jan 28 22:31:17 2025 +0100 +++ b/Small_CPU/Inc/uart.h Wed Jan 29 17:21:20 2025 +0100 @@ -83,9 +83,8 @@ void UART_MUX_SelectAddress(uint8_t muxAddress); void UART_SendCmdString(uint8_t *cmdString); void UART_SendCmdUbx(const uint8_t *cmd, uint8_t len); -void UART_ReadData(uint8_t sensorType); +void UART_ReadData(uint8_t sensorType, uint8_t flush); void UART_WriteData(sUartComCtrl* pUartCtrl); -void UART_FlushRxBuffer(void); void UART_ChangeBaudrate(uint32_t newBaudrate); uint8_t UART_isComActive(uint8_t sensorId); uint8_t UART_isEndIndication(sUartComCtrl* pCtrl, uint8_t index); diff -r 142f3d0363b3 -r 0b81ac558e89 Small_CPU/Src/externalInterface.c --- a/Small_CPU/Src/externalInterface.c Tue Jan 28 22:31:17 2025 +0100 +++ b/Small_CPU/Src/externalInterface.c Wed Jan 29 17:21:20 2025 +0100 @@ -1156,7 +1156,7 @@ if(externalInterface_SensorState[activeSensorId] != UART_COMMON_INIT) { - UART_ReadData(pmap[activeSensorId]); + UART_ReadData(pmap[activeSensorId], 0); UART_WriteData(&Uart1Ctrl); } if(externalInterface_SensorState[activeSensorId] == UART_COMMON_INIT) @@ -1263,16 +1263,6 @@ break; } } -#if 0 - else - { - if(((time_elapsed_ms(lastRequestTick,tick) > (externalInterfaceMuxReqIntervall - 100)) - && externalInterface_SensorState[activeSensorId] = UART_COMMON_IDLE)) - { - externalInterface_ReadAndSwitch(); - } - } -#endif } #if 0 diff -r 142f3d0363b3 -r 0b81ac558e89 Small_CPU/Src/uart.c --- a/Small_CPU/Src/uart.c Tue Jan 28 22:31:17 2025 +0100 +++ b/Small_CPU/Src/uart.c Wed Jan 29 17:21:20 2025 +0100 @@ -317,6 +317,7 @@ Uart1Ctrl.rxReadIndex = 0; Uart1Ctrl.rxWriteIndex = 0; Uart1Ctrl.dmaRxActive = 0; + Uart1Ctrl.dmaTxActive = 0; Uart1Ctrl.txBufferQueLen = 0; } @@ -390,7 +391,7 @@ return ret; } -void UART_ReadData(uint8_t sensorType) +void UART_ReadData(uint8_t sensorType, uint8_t flush) /* flush = 1 skips processing of data => data is discarded */ { uint8_t localRX; uint8_t futureIndex; @@ -422,7 +423,6 @@ moreData = 1; } - //if((!isEndIndication(pUartCtrl, localRX)) || (!isEndIndication(pUartCtrl,futureIndex))) do if((!UART_isEndIndication(pUartCtrl, localRX)) || (moreData)) do { @@ -492,36 +492,6 @@ } } -void UART_FlushRxBuffer(void) -{ - uint8_t futureIndex = Uart1Ctrl.rxReadIndex + 1; - - if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) - { - futureIndex = 0; - } - while((rxBuffer[Uart1Ctrl.rxReadIndex] != BUFFER_NODATA_LOW) && (rxBuffer[futureIndex] != BUFFER_NODATA_HIGH)) - { - if(Uart1Ctrl.rxReadIndex % 2) - { - rxBuffer[Uart1Ctrl.rxReadIndex++] = BUFFER_NODATA_HIGH; - } - else - { - rxBuffer[Uart1Ctrl.rxReadIndex++] = BUFFER_NODATA_LOW; - } - if(Uart1Ctrl.rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) - { - Uart1Ctrl.rxReadIndex = 0; - } - futureIndex++; - if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) - { - futureIndex = 0; - } - } -} - uint8_t UART_isComActive(uint8_t sensorId) { uint8_t active = 1; diff -r 142f3d0363b3 -r 0b81ac558e89 Small_CPU/Src/uartProtocol_Co2.c --- a/Small_CPU/Src/uartProtocol_Co2.c Tue Jan 28 22:31:17 2025 +0100 +++ b/Small_CPU/Src/uartProtocol_Co2.c Wed Jan 29 17:21:20 2025 +0100 @@ -83,7 +83,7 @@ { CO2Connected = 0; externalInterface_SetCO2Scale(0.0); - UART_clearRxBuffer(&Uart1Ctrl); + UART_ReadData(SENSOR_CO2, 1); /* flush buffer */ UART_StartDMA_Receiption(&Uart1Ctrl); localComState = UART_CO2_SETUP; } @@ -110,8 +110,16 @@ //if(cmdLength == 0) /* poll data */ if(localComState == UART_CO2_IDLE) { - uartCo2_SendCmd(CO2CMD_GETDATA, cmdString, &cmdLength); - localComState = UART_CO2_OPERATING; + if(externalInterface_GetCO2Scale() == 0.0) + { + uartCo2_SendCmd(CO2CMD_GETSCALE, cmdString, &cmdLength); + localComState = UART_CO2_SETUP; + } + else + { + uartCo2_SendCmd(CO2CMD_GETDATA, cmdString, &cmdLength); + localComState = UART_CO2_OPERATING; + } } else /* resend last command */ { @@ -207,6 +215,7 @@ default: rxState = CO2RX_Ready; break; } + rxState = CO2RX_Ready; } if(rxState != CO2RX_Data0) /* reset state machine because message in wrong format */ { diff -r 142f3d0363b3 -r 0b81ac558e89 Small_CPU/Src/uartProtocol_O2.c --- a/Small_CPU/Src/uartProtocol_O2.c Tue Jan 28 22:31:17 2025 +0100 +++ b/Small_CPU/Src/uartProtocol_O2.c Wed Jan 29 17:21:20 2025 +0100 @@ -75,6 +75,7 @@ static uint8_t lastComState = 0; static uint8_t lastActiveSensor = 0xFF; + uint8_t *pmap = externalInterface_GetSensorMapPointer(0); uint8_t activeSensor = externalInterface_GetActiveUartSensor(); uartO2Status_t localComState = externalInterface_GetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET); @@ -96,7 +97,7 @@ { localComState = UART_O2_IDLE; } - UART_FlushRxBuffer(); + UART_ReadData(SENSOR_DIGO2, 1); /* flush buffer */ } if(localComState == UART_O2_INIT) @@ -106,10 +107,13 @@ localComState = UART_O2_CHECK; lastComState = UART_O2_CHECK; - UART_clearRxBuffer(&Uart1Ctrl); + UART_ReadData(SENSOR_DIGO2, 1); /* flush buffer */ uartO2_SetupCmd(localComState,cmdString,&cmdLength); UART_SendCmdString(cmdString); - HAL_Delay(80); + if(pmap[EXT_INTERFACE_SENSOR_CNT-1] != SENSOR_MUX) /* stand alone mode => add some time for sensor com setup */ + { + HAL_Delay(80); + } rxState = O2RX_CONFIRM; respondErrorDetected = 0; digO2Connected = 0; diff -r 142f3d0363b3 -r 0b81ac558e89 Small_CPU/Src/uart_Internal.c --- a/Small_CPU/Src/uart_Internal.c Tue Jan 28 22:31:17 2025 +0100 +++ b/Small_CPU/Src/uart_Internal.c Wed Jan 29 17:21:20 2025 +0100 @@ -165,7 +165,7 @@ if(gnssState != UART_GNSS_INIT) { - UART_ReadData(SENSOR_GNSS); + UART_ReadData(SENSOR_GNSS, 0); UART_WriteData(&Uart6Ctrl); } if(gnssState == UART_GNSS_INIT)