comparison Small_CPU/Src/uartProtocol_O2.c @ 976:0b81ac558e89 Evo_2_23

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.
author Ideenmodellierer
date Wed, 29 Jan 2025 17:21:20 +0100 (2 months ago)
parents 142f3d0363b3
children
comparison
equal deleted inserted replaced
975:142f3d0363b3 976:0b81ac558e89
73 void uartO2_Control(void) 73 void uartO2_Control(void)
74 { 74 {
75 static uint8_t lastComState = 0; 75 static uint8_t lastComState = 0;
76 static uint8_t lastActiveSensor = 0xFF; 76 static uint8_t lastActiveSensor = 0xFF;
77 77
78 uint8_t *pmap = externalInterface_GetSensorMapPointer(0);
78 uint8_t activeSensor = externalInterface_GetActiveUartSensor(); 79 uint8_t activeSensor = externalInterface_GetActiveUartSensor();
79 80
80 uartO2Status_t localComState = externalInterface_GetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET); 81 uartO2Status_t localComState = externalInterface_GetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET);
81 externalInterface_GetSensorData(activeSensor + EXT_INTERFACE_MUX_OFFSET, (uint8_t*)&tmpSensorDataDiveO2); 82 externalInterface_GetSensorData(activeSensor + EXT_INTERFACE_MUX_OFFSET, (uint8_t*)&tmpSensorDataDiveO2);
82 83
94 } 95 }
95 if(localComState == UART_O2_CHECK) 96 if(localComState == UART_O2_CHECK)
96 { 97 {
97 localComState = UART_O2_IDLE; 98 localComState = UART_O2_IDLE;
98 } 99 }
99 UART_FlushRxBuffer(); 100 UART_ReadData(SENSOR_DIGO2, 1); /* flush buffer */
100 } 101 }
101 102
102 if(localComState == UART_O2_INIT) 103 if(localComState == UART_O2_INIT)
103 { 104 {
104 memset((char*) &tmpSensorDataDiveO2, 0, sizeof(tmpSensorDataDiveO2)); 105 memset((char*) &tmpSensorDataDiveO2, 0, sizeof(tmpSensorDataDiveO2));
105 externalInterface_SetSensorData(0xFF,(uint8_t*)&tmpSensorDataDiveO2); 106 externalInterface_SetSensorData(0xFF,(uint8_t*)&tmpSensorDataDiveO2);
106 107
107 localComState = UART_O2_CHECK; 108 localComState = UART_O2_CHECK;
108 lastComState = UART_O2_CHECK; 109 lastComState = UART_O2_CHECK;
109 UART_clearRxBuffer(&Uart1Ctrl); 110 UART_ReadData(SENSOR_DIGO2, 1); /* flush buffer */
110 uartO2_SetupCmd(localComState,cmdString,&cmdLength); 111 uartO2_SetupCmd(localComState,cmdString,&cmdLength);
111 UART_SendCmdString(cmdString); 112 UART_SendCmdString(cmdString);
112 HAL_Delay(80); 113 if(pmap[EXT_INTERFACE_SENSOR_CNT-1] != SENSOR_MUX) /* stand alone mode => add some time for sensor com setup */
114 {
115 HAL_Delay(80);
116 }
113 rxState = O2RX_CONFIRM; 117 rxState = O2RX_CONFIRM;
114 respondErrorDetected = 0; 118 respondErrorDetected = 0;
115 digO2Connected = 0; 119 digO2Connected = 0;
116 } 120 }
117 else 121 else