diff --git a/Host/Source/MicroBoot/interfaces/uart/XcpTransport.pas b/Host/Source/MicroBoot/interfaces/uart/XcpTransport.pas index 2f7222d2..90db84dc 100644 --- a/Host/Source/MicroBoot/interfaces/uart/XcpTransport.pas +++ b/Host/Source/MicroBoot/interfaces/uart/XcpTransport.pas @@ -195,6 +195,8 @@ var msgData : array of Byte; resLen : byte; cnt : byte; + rxCnt : byte; + dwEnd : DWord; begin // init the return value result := false; @@ -228,15 +230,42 @@ begin Exit; end; - // configure reception timeout. timeout = (MULTIPLIER) * number_of_bytes + CONSTANT + // give application the opportunity to process the messages + Application.ProcessMessages; + + // confgure the reception timeout. timeout = (MULTIPLIER) * number_of_bytes + CONSTANT sciDriver.Timeouts.ReadTotalConstant := timeOutms; sciDriver.Timeouts.ReadTotalMultiplier := 0; + // compute timeout time for receiving the response + dwEnd := GetTickCount + timeOutms; + // receive the first byte which should hold the packet length if sciDriver.Read(resLen, 1) = 1 then begin - // receive the actual packet data - if sciDriver.Read(packetData[0], resLen) = resLen then + // init the number of received bytes to 0 + rxCnt := 0; + packetLen := 0; + + // re-confgure the reception timeout now that the total packet length is known. + // timeout = (MULTIPLIER) * number_of_bytes + CONSTANT + sciDriver.Timeouts.ReadTotalConstant := 0; + sciDriver.Timeouts.ReadTotalMultiplier := timeOutms div resLen; + + // attempt to receive the bytes of the response packet one by one + while (rxCnt < resLen) and (GetTickCount < dwEnd) do + begin + // receive the next byte + if sciDriver.Read(packetData[rxCnt], 1) = 1 then + begin + // increment counter + rxCnt := rxCnt + 1; + end; + end; + + // check to see if all bytes were received. if not, then a timeout must have + // happened. + if rxCnt = resLen then begin packetLen := resLen; result := true; diff --git a/Host/Source/MicroBoot/interfaces/usb/XcpTransport.pas b/Host/Source/MicroBoot/interfaces/usb/XcpTransport.pas index 1ac833f1..c5e3cdb2 100644 --- a/Host/Source/MicroBoot/interfaces/usb/XcpTransport.pas +++ b/Host/Source/MicroBoot/interfaces/usb/XcpTransport.pas @@ -188,9 +188,6 @@ begin // compute timeout time dwEnd := GetTickCount + timeOutms; - // configure timeout for first byte - //sciDriver.InputTimeout := timeOutms; - // receive the first byte which holds the packet length if UblReceive(Addr(resLen), 1, timeOutms) = UBL_OKAY then begin diff --git a/Host/openblt_uart.dll b/Host/openblt_uart.dll index 77ac705c..e456b858 100644 Binary files a/Host/openblt_uart.dll and b/Host/openblt_uart.dll differ diff --git a/Host/openblt_uart.ini b/Host/openblt_uart.ini index a8b55361..12b4d97c 100644 --- a/Host/openblt_uart.ini +++ b/Host/openblt_uart.ini @@ -1,5 +1,5 @@ [sci] -port=5 +port=3 baudrate=8 [xcp] seedkey=FeaserKey.dll