Mercurial > public > ostc4
comparison Small_CPU/Src/uart.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 (8 weeks ago) |
parents | 3029f0332f4f |
children |
comparison
equal
deleted
inserted
replaced
975:142f3d0363b3 | 976:0b81ac558e89 |
---|---|
315 | 315 |
316 UART_clearRxBuffer(&Uart1Ctrl); | 316 UART_clearRxBuffer(&Uart1Ctrl); |
317 Uart1Ctrl.rxReadIndex = 0; | 317 Uart1Ctrl.rxReadIndex = 0; |
318 Uart1Ctrl.rxWriteIndex = 0; | 318 Uart1Ctrl.rxWriteIndex = 0; |
319 Uart1Ctrl.dmaRxActive = 0; | 319 Uart1Ctrl.dmaRxActive = 0; |
320 Uart1Ctrl.dmaTxActive = 0; | |
320 Uart1Ctrl.txBufferQueLen = 0; | 321 Uart1Ctrl.txBufferQueLen = 0; |
321 } | 322 } |
322 | 323 |
323 void UART_HandleRxComplete(sUartComCtrl* pUartCtrl) | 324 void UART_HandleRxComplete(sUartComCtrl* pUartCtrl) |
324 { | 325 { |
388 } | 389 } |
389 } | 390 } |
390 | 391 |
391 return ret; | 392 return ret; |
392 } | 393 } |
393 void UART_ReadData(uint8_t sensorType) | 394 void UART_ReadData(uint8_t sensorType, uint8_t flush) /* flush = 1 skips processing of data => data is discarded */ |
394 { | 395 { |
395 uint8_t localRX; | 396 uint8_t localRX; |
396 uint8_t futureIndex; | 397 uint8_t futureIndex; |
397 uint8_t moreData = 0; | 398 uint8_t moreData = 0; |
398 | 399 |
420 if(!UART_isEndIndication(pUartCtrl, futureIndex)) | 421 if(!UART_isEndIndication(pUartCtrl, futureIndex)) |
421 { | 422 { |
422 moreData = 1; | 423 moreData = 1; |
423 } | 424 } |
424 | 425 |
425 //if((!isEndIndication(pUartCtrl, localRX)) || (!isEndIndication(pUartCtrl,futureIndex))) do | |
426 if((!UART_isEndIndication(pUartCtrl, localRX)) || (moreData)) | 426 if((!UART_isEndIndication(pUartCtrl, localRX)) || (moreData)) |
427 do | 427 do |
428 { | 428 { |
429 while((!UART_isEndIndication(pUartCtrl, localRX)) || (moreData)) | 429 while((!UART_isEndIndication(pUartCtrl, localRX)) || (moreData)) |
430 { | 430 { |
490 pUartCtrl->pHandle->RxState = HAL_UART_STATE_READY; | 490 pUartCtrl->pHandle->RxState = HAL_UART_STATE_READY; |
491 pUartCtrl->dmaRxActive = 0; | 491 pUartCtrl->dmaRxActive = 0; |
492 } | 492 } |
493 } | 493 } |
494 | 494 |
495 void UART_FlushRxBuffer(void) | |
496 { | |
497 uint8_t futureIndex = Uart1Ctrl.rxReadIndex + 1; | |
498 | |
499 if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
500 { | |
501 futureIndex = 0; | |
502 } | |
503 while((rxBuffer[Uart1Ctrl.rxReadIndex] != BUFFER_NODATA_LOW) && (rxBuffer[futureIndex] != BUFFER_NODATA_HIGH)) | |
504 { | |
505 if(Uart1Ctrl.rxReadIndex % 2) | |
506 { | |
507 rxBuffer[Uart1Ctrl.rxReadIndex++] = BUFFER_NODATA_HIGH; | |
508 } | |
509 else | |
510 { | |
511 rxBuffer[Uart1Ctrl.rxReadIndex++] = BUFFER_NODATA_LOW; | |
512 } | |
513 if(Uart1Ctrl.rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
514 { | |
515 Uart1Ctrl.rxReadIndex = 0; | |
516 } | |
517 futureIndex++; | |
518 if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
519 { | |
520 futureIndex = 0; | |
521 } | |
522 } | |
523 } | |
524 | |
525 uint8_t UART_isComActive(uint8_t sensorId) | 495 uint8_t UART_isComActive(uint8_t sensorId) |
526 { | 496 { |
527 uint8_t active = 1; | 497 uint8_t active = 1; |
528 | 498 |
529 if(time_elapsed_ms(LastCmdRequestTick, HAL_GetTick()) > 300) /* UART activity should be inactive 300ms after last command */ | 499 if(time_elapsed_ms(LastCmdRequestTick, HAL_GetTick()) > 300) /* UART activity should be inactive 300ms after last command */ |