start refactoring transmitting

This commit is contained in:
Wolfgang Hottgenroth 2020-11-25 13:20:37 +01:00
parent c9b5f16542
commit e2ed18e71d
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F

View File

@ -266,22 +266,29 @@ void mbusCommISR() {
// RXNEIE doesn't need to be considered since it is always on and more over the // RXNEIE doesn't need to be considered since it is always on and more over the
// RXNE flag is cleared by reading the DR, which is done in any case // RXNE flag is cleared by reading the DR, which is done in any case
if (((isrflags & USART_SR_RXNE) != RESET) || ((isrflags & (USART_SR_ORE | USART_SR_FE | USART_SR_PE)) != RESET)) { if (((isrflags & USART_SR_RXNE) != RESET) || ((isrflags & (USART_SR_ORE | USART_SR_FE | USART_SR_PE)) != RESET)) {
// Error flags are only valid together with the RX flag.
// They will be cleared by reading SR (already done above) followed by reading DR (below).
bool errorFound = false;
if ((isrflags & USART_SR_ORE) != RESET) { if ((isrflags & USART_SR_ORE) != RESET) {
show(DEBUG_2, TOGGLE); show(DEBUG_2, TOGGLE);
mbusCommStats.uartOverrunCnt += 1; mbusCommStats.uartOverrunCnt += 1;
errorFound = true;
} }
if ((isrflags & USART_SR_FE) != RESET) { if ((isrflags & USART_SR_FE) != RESET) {
mbusCommStats.uartFramingErrCnt += 1; mbusCommStats.uartFramingErrCnt += 1;
errorFound = true;
} }
if ((isrflags & USART_SR_PE) != RESET) { if ((isrflags & USART_SR_PE) != RESET) {
mbusCommStats.uartParityErrCnt += 1; mbusCommStats.uartParityErrCnt += 1;
errorFound = true;
} }
mbusCommStats.uartOctetCnt += 1; mbusCommStats.uartOctetCnt += 1;
// it is required to read the DR in any case here, not only when the buffer has space // it is required to read the DR in any case here, not only when the buffer has space
// otherwise the interrupt flag won't be disabled, particularly important in case of // otherwise the interrupt flag won't be disabled, particularly important in case of
// ORE // ORE
uint8_t data = (uint8_t)(mbusUart.Instance->DR & (uint8_t)0x00FF); uint8_t data = (uint8_t)(mbusUart.Instance->DR & (uint8_t)0x00FF);
if (mbusCommHandle.receiveBuffer.writeIdx < mbusCommHandle.receiveBuffer.size) { if ((! errorFound) &&
(mbusCommHandle.receiveBuffer.writeIdx < mbusCommHandle.receiveBuffer.size)) {
mbusCommHandle.receiveBuffer.buffer[mbusCommHandle.receiveBuffer.writeIdx] = data; mbusCommHandle.receiveBuffer.buffer[mbusCommHandle.receiveBuffer.writeIdx] = data;
mbusCommHandle.receiveBuffer.writeIdx += 1; mbusCommHandle.receiveBuffer.writeIdx += 1;
} }