From 2a51a1db7cd3224bc843023df1a481f93a5389fb Mon Sep 17 00:00:00 2001 From: skarg Date: Mon, 12 Mar 2012 21:26:53 +0000 Subject: [PATCH] Added MS/TP tweak to improve byte reception and processing at higher baud rates and larger packet sizes. Thank you Peter Mc Shane! --- bacnet-stack/ports/at91sam7s/dlmstp.c | 8 ++++++-- bacnet-stack/ports/at91sam7s/rs485.c | 4 +++- bacnet-stack/ports/stm32f10x/dlmstp.c | 16 +++++++++++----- bacnet-stack/ports/stm32f10x/rs485.c | 4 +++- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/bacnet-stack/ports/at91sam7s/dlmstp.c b/bacnet-stack/ports/at91sam7s/dlmstp.c index c7fd1ed7..97001c9c 100644 --- a/bacnet-stack/ports/at91sam7s/dlmstp.c +++ b/bacnet-stack/ports/at91sam7s/dlmstp.c @@ -1255,11 +1255,15 @@ uint16_t dlmstp_receive( InputBuffer = pdu; InputBufferSize = max_pdu; } - /* only do receive state machine while we don't have a frame */ - if ((MSTP_Flag.ReceivedValidFrame == false) && + while ((MSTP_Flag.ReceivedValidFrame == false) && (MSTP_Flag.ReceivedValidFrameNotForUs == false) && (MSTP_Flag.ReceivedInvalidFrame == false)) { + /* only do receive state machine while we don't have a frame */ MSTP_Receive_Frame_FSM(); + /* process another byte, if available */ + if (!RS485_DataAvailable(NULL)) { + break; + } } if (MSTP_Flag.ReceivedValidFrameNotForUs) { MSTP_Flag.ReceivedValidFrameNotForUs = false; diff --git a/bacnet-stack/ports/at91sam7s/rs485.c b/bacnet-stack/ports/at91sam7s/rs485.c index 98676a51..db1b5806 100644 --- a/bacnet-stack/ports/at91sam7s/rs485.c +++ b/bacnet-stack/ports/at91sam7s/rs485.c @@ -255,7 +255,9 @@ bool RS485_DataAvailable( if (RS485_Interface->US_CSR & AT91C_US_RXRDY) { /* data is available */ - *DataRegister = RS485_Interface->US_RHR; + if (DataRegister) { + *DataRegister = RS485_Interface->US_RHR; + } DataAvailable = true; /* LED ON */ pPIO->PIO_CODR = LED2; diff --git a/bacnet-stack/ports/stm32f10x/dlmstp.c b/bacnet-stack/ports/stm32f10x/dlmstp.c index 5c00f24a..99fd7ccd 100644 --- a/bacnet-stack/ports/stm32f10x/dlmstp.c +++ b/bacnet-stack/ports/stm32f10x/dlmstp.c @@ -1504,11 +1504,17 @@ uint16_t dlmstp_receive( if (Receive_State == MSTP_RECEIVE_STATE_IDLE) { transmitting = MSTP_Transmit_FSM(); } - /* only do receive state machine while we don't have a frame */ - if ((MSTP_Flag.ReceivedValidFrame == false) && - (MSTP_Flag.ReceivedValidFrameNotForUs == false) && - (MSTP_Flag.ReceivedInvalidFrame == false) && (transmitting == false)) { - MSTP_Receive_Frame_FSM(); + if (transmitting == false) { + while ((MSTP_Flag.ReceivedValidFrame == false) && + (MSTP_Flag.ReceivedValidFrameNotForUs == false) && + (MSTP_Flag.ReceivedInvalidFrame == false)) { + /* only do receive state machine while we don't have a frame */ + MSTP_Receive_Frame_FSM(); + /* process another byte, if available */ + if (!rs485_byte_available(NULL)) { + break; + } + } } /* only do master state machine while rx is idle */ if ((Receive_State == MSTP_RECEIVE_STATE_IDLE) && (transmitting == false)) { diff --git a/bacnet-stack/ports/stm32f10x/rs485.c b/bacnet-stack/ports/stm32f10x/rs485.c index acc10cda..d85247af 100644 --- a/bacnet-stack/ports/stm32f10x/rs485.c +++ b/bacnet-stack/ports/stm32f10x/rs485.c @@ -141,7 +141,9 @@ bool rs485_byte_available( bool data_available = false; /* return value */ if (!FIFO_Empty(&Receive_Buffer)) { - *data_register = FIFO_Get(&Receive_Buffer); + if (data_register) { + *data_register = FIFO_Get(&Receive_Buffer); + } timer_elapsed_start(&Silence_Timer); data_available = true; led_rx_on_interval(10);